Crate custom_formatter

Crate custom_formatter 

Source
Expand description

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.

Macros§

__custom_format_args_internal
custom_format
Create any type that is the output of a CustomFormatter, from a formatting string.
custom_format_args
Create an Arguments from a formatting string.

Structs§

Argument
Represents a single formatting argument.
Arguments
A collection of format arguments. Implements Iterator<Item = (&'static str, Option<Argument<'a, F>>). Construct this using custom_format_args.
DebugFormatter
An example formatter. Can format anything with a Debug implementation. Formats into a String.
DisplayFormatter
An example formatter. Can format anything with a Display implementation. Formats into a String.

Traits§

CustomFormatter
A custom formatting strategy.
Format

Functions§

custom_format
Format into a type, using the given formatting strategy.
custom_format_infer
Format into a T, possibly inferring type from surroundings.