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.
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 with0x
. -
The binary formater (eg:
formatc!("{:#b}", FOO)
): prefixes numbers with0b
.`
Implementations§
source§impl FormattingFlags
impl FormattingFlags
sourcepub const NEW: Self = _
pub const NEW: Self = _
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,
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 number formatting 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 number formatting to NumberFormatting::Hexadecimal
.
This means that numbers are written as uppercase hexadecimal.
sourcepub const fn set_lower_hexadecimal(self) -> Self
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.
sourcepub const fn set_binary(self) -> Self
pub const fn set_binary(self) -> Self
Sets the number formatting 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§
source§impl Clone for FormattingFlags
impl Clone for FormattingFlags
source§fn clone(&self) -> FormattingFlags
fn clone(&self) -> FormattingFlags
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for FormattingFlags
impl Debug for FormattingFlags
impl Copy for FormattingFlags
Auto Trait Implementations§
impl Freeze for FormattingFlags
impl RefUnwindSafe for FormattingFlags
impl Send for FormattingFlags
impl Sync for FormattingFlags
impl Unpin for FormattingFlags
impl UnwindSafe for FormattingFlags
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)