1 unstable release
new 0.1.0 | Feb 17, 2025 |
---|
#4 in #format-args
47 downloads per month
13KB
229 lines
custom_formatter
Provides a generalized version of format_args!
(and format!
) that allows you to format into
arbitrary types. See the documentation for more.
lib.rs
:
A generalized version of format_args, that allows you to format into arbitrary types, instead of just strings.
For examples, see the examples subdirectory. color.rs
provides a simple motivation.
To get started, implement CustomFormatter
. For types with a single canonical way to format,
implement CustomFormatter
directly on the type with Output = Self
. For types with multiple
different formatting strategies (such as Debug and Display for strings), implement
CustomFormatter
on a marker type instead.
Then, implement Format<F>
on types that can be formatted into your custom formatter.
Finally, you can use the provided macro, custom_format!
, in a similar manner to format
, to
create instances of the type.
Dependencies
~1.5MB
~38K SLoC