Struct const_format::fmt::FormattingFlags
source · [−]pub struct FormattingFlags { /* private fields */ }
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 with0x
. -
The binary formater (eg:
formatc!("{:#b}", FOO)
): prefixes numbers with0b
.`
Implementations
sourceimpl FormattingFlags
impl FormattingFlags
sourcepub const NEW: Self = Self {
num_fmt: NumberFormatting::Decimal,
is_alternate: false,
}
pub const NEW: Self = Self { num_fmt: NumberFormatting::Decimal, is_alternate: false, }
Constructs a FormattingFlags
with these values:
-
number formatting: NumberFormatting::Decimal
-
is alternate: false
sourcepub const fn new() -> Self
pub const fn new() -> Self
Constructs a FormattingFlags
with these values:
-
number formatting: NumberFormatting::Decimal
-
is alternate: false
sourcepub const fn set_num_fmt(self, num_fmt: NumberFormatting) -> Self
pub const fn set_num_fmt(self, num_fmt: NumberFormatting) -> Self
Sets the integer formatting num_fmt,
This usually doesn’t affect the outputted text in display formatting.
sourcepub const fn set_decimal(self) -> Self
pub const fn set_decimal(self) -> Self
Sets the formatting num_fmt to NumberFormatting::Decimal
.
This means that numbers are written as decimal.
sourcepub const fn set_hexadecimal(self) -> Self
pub const fn set_hexadecimal(self) -> Self
Sets the formatting num_fmt to NumberFormatting::Hexadecimal
.
This means that numbers are written as hexadecimal.
sourcepub const fn set_binary(self) -> Self
pub const fn set_binary(self) -> Self
Sets the formatting num_fmt to NumberFormatting::Binary
.
This means that numbers are written as binary.
sourcepub const fn set_alternate(self, is_alternate: bool) -> Self
pub const fn set_alternate(self, is_alternate: bool) -> Self
Sets whether the formatting flag is enabled.
sourcepub const fn num_fmt(self) -> NumberFormatting
pub const fn num_fmt(self) -> NumberFormatting
Gets the current NumberFormatting
.
sourcepub const fn is_alternate(self) -> bool
pub const fn is_alternate(self) -> bool
Gets whether the alternate flag is enabled
Trait Implementations
sourceimpl Clone for FormattingFlags
impl Clone for FormattingFlags
sourcefn clone(&self) -> FormattingFlags
fn clone(&self) -> FormattingFlags
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for FormattingFlags
impl Debug for FormattingFlags
impl Copy for FormattingFlags
Auto Trait Implementations
impl RefUnwindSafe for FormattingFlags
impl Send for FormattingFlags
impl Sync for FormattingFlags
impl Unpin for FormattingFlags
impl UnwindSafe for FormattingFlags
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more