pub struct FormattingFlags { /* private fields */ }
Available on crate feature fmt only.
Expand description

This type bundles configuration for how to format data into strings, including.

Number formatting

How numbers are formatted in debug formatters, It can be accessed with the num_fmt method, and set with the set_num_fmt method.

Each type of number formatting corresponds to a NumberFormatting variant:

  • NumberFormatting::Decimal (eg: formatc!("{:?}", FOO)): formats numbers as decimal.

  • NumberFormatting::Hexadecimal (eg: formatc!("{:x}", FOO)): formats numbers as hexadecimal.

  • NumberFormatting::Binary (eg: formatc!("{:b}", FOO)): formats numbers as binary.

Hexadecimal or binary formatting in the formatting string from this crate imply debug formatting, and can be used to for example print an array of binary numbers.

Alternate flag

A flag that types can use to be formatted differently when it’s enabled, checked with the .is_alternate() method.

The default behavior when it is enabled is this:

  • The Debug formater (eg: formatc!("{:#?}", FOO)): pretty print structs and enums.

  • The hexadecimal formater (eg: formatc!("{:#x}", FOO)): prefixes numbers with 0x.

  • The binary formater (eg: formatc!("{:#b}", FOO)): prefixes numbers with 0b.`

Implementations

Constructs a FormattingFlags with these values:

  • number formatting: NumberFormatting::Decimal

  • is alternate: false

Constructs a FormattingFlags with these values:

  • number formatting: NumberFormatting::Decimal

  • is alternate: false

Sets the integer formatting num_fmt,

This usually doesn’t affect the outputted text in display formatting.

Sets the formatting num_fmt to NumberFormatting::Decimal.

This means that numbers are written as decimal.

Sets the formatting num_fmt to NumberFormatting::Hexadecimal.

This means that numbers are written as hexadecimal.

Sets the formatting num_fmt to NumberFormatting::Binary.

This means that numbers are written as binary.

Sets whether the formatting flag is enabled.

Gets the current NumberFormatting.

Gets whether the alternate flag is enabled

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.