[][src]Struct const_format::fmt::FormattingFlags

#[must_use]pub struct FormattingFlags { /* fields omitted */ }
This is supported on crate feature fmt only.

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

impl FormattingFlags[src]

pub const NEW: Self[src]

Constructs a FormattingFlags with these values:

  • number formatting: NumberFormatting::Decimal

  • is alternate: false

pub const fn new() -> Self[src]

Constructs a FormattingFlags with these values:

  • number formatting: NumberFormatting::Decimal

  • is alternate: false

pub const fn set_num_fmt(mut self: Self, num_fmt: NumberFormatting) -> Self[src]

Sets the integer formatting num_fmt,

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

pub const fn set_decimal(mut self: Self) -> Self[src]

Sets the formatting num_fmt to NumberFormatting::Decimal.

This means that numbers are written as decimal.

pub const fn set_hexadecimal(mut self: Self) -> Self[src]

Sets the formatting num_fmt to NumberFormatting::Hexadecimal.

This means that numbers are written as hexadecimal.

pub const fn set_binary(mut self: Self) -> Self[src]

Sets the formatting num_fmt to NumberFormatting::Binary.

This means that numbers are written as binary.

pub const fn set_alternate(mut self: Self, is_alternate: bool) -> Self[src]

Sets whether the formatting flag is enabled.

pub const fn num_fmt(self) -> NumberFormatting[src]

Gets the current NumberFormatting.

pub const fn is_alternate(self) -> bool[src]

Gets whether the alternate flag is enabled

Trait Implementations

impl Clone for FormattingFlags[src]

impl Copy for FormattingFlags[src]

impl Debug for FormattingFlags[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.