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.

Note: Lowercase hexadecimal formatting requires calling the set_lower_hexadecimal method.

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§

source§

impl FormattingFlags

source

pub const NEW: Self = _

Constructs a FormattingFlags with these values:

  • number formatting: NumberFormatting::Decimal

  • is alternate: false

source

pub const fn new() -> Self

Constructs a FormattingFlags with these values:

  • number formatting: NumberFormatting::Decimal

  • is alternate: false

source

pub const fn set_num_fmt(self, num_fmt: NumberFormatting) -> Self

Sets the integer formatting,

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

source

pub const fn set_decimal(self) -> Self

Sets the number formatting to NumberFormatting::Decimal.

This means that numbers are written as decimal.

source

pub const fn set_hexadecimal(self) -> Self

Sets the number formatting to NumberFormatting::Hexadecimal.

This means that numbers are written as uppercase hexadecimal.

source

pub const fn set_lower_hexadecimal(self) -> Self

Sets the number formatting to NumberFormatting::Hexadecimal, and uses lowercase for alphabetic hexadecimal digits.

This means that numbers are written as lowercase hexadecimal.

source

pub const fn set_binary(self) -> Self

Sets the number formatting to NumberFormatting::Binary.

This means that numbers are written as binary.

source

pub const fn set_alternate(self, is_alternate: bool) -> Self

Sets whether the formatting flag is enabled.

source

pub const fn num_fmt(self) -> NumberFormatting

Gets the current NumberFormatting.

source

pub const fn is_alternate(self) -> bool

Gets whether the alternate flag is enabled

Trait Implementations§

source§

impl Clone for FormattingFlags

source§

fn clone(&self) -> FormattingFlags

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for FormattingFlags

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Copy for FormattingFlags

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.