pub struct FormattingOptions {
flags: u32,
width: u16,
precision: u16,
}
formatting_options
#118117)Expand description
FieldsΒ§
Β§flags: u32
formatting_options
#118117)Flags, with the following bit fields:
31 30 29 28 27 26 25 24 23 22 21 20 0
βββββ¬ββββββββ¬ββββ¬ββββ¬ββββ¬ββββ¬ββββ¬ββββ¬ββββ¬ββββ¬βββββββββββββββββββββββββββββββββββ
β 1 β align β p β w β X?β x?β'0'β # β - β + β fill β
βββββ΄ββββββββ΄ββββ΄ββββ΄ββββ΄ββββ΄ββββ΄ββββ΄ββββ΄ββββ΄βββββββββββββββββββββββββββββββββββ
β β β β βββ¬ββββββββββββββββββββ βββ¬βββββββββββββββββββββββββββββββ
β β β β β ββ The fill character (21 bits char).
β β β β ββ The debug upper/lower hex, zero pad, alternate, and plus/minus flags.
β β β ββ Whether a width is set. (The value is stored separately.)
β β ββ Whether a precision is set. (The value is stored separately.)
β ββ 0: Align left. (<)
β ββ 1: Align right. (>)
β ββ 2: Align center. (^)
β ββ 3: Alignment not set. (default)
ββ Always set.
This makes it possible to distinguish formatting flags from
a &str size when stored in (the upper bits of) the same field.
(fmt::Arguments will make use of this property in the future.)
width: u16
formatting_options
#118117)Width if width flag (bit 27) above is set. Otherwise, always 0.
precision: u16
formatting_options
#118117)Precision if precision flag (bit 28) above is set. Otherwise, always 0.
ImplementationsΒ§
SourceΒ§impl FormattingOptions
impl FormattingOptions
Sourcepub const fn new() -> Self
π¬This is a nightly-only experimental API. (formatting_options
#118117)
pub const fn new() -> Self
formatting_options
#118117)Construct a new FormatterBuilder
with the supplied Write
trait
object for output that is equivalent to the {}
formatting
specifier:
- no flags,
- filled with spaces,
- no alignment,
- no width,
- no precision, and
- no
DebugAsHex
output mode.
Sourcepub fn sign(&mut self, sign: Option<Sign>) -> &mut Self
π¬This is a nightly-only experimental API. (formatting_options
#118117)
pub fn sign(&mut self, sign: Option<Sign>) -> &mut Self
formatting_options
#118117)Sets or removes the sign (the +
or the -
flag).
+
: This is intended for numeric types and indicates that the sign should always be printed. By default only the negative sign of signed values is printed, and the sign of positive or unsigned values is omitted. This flag indicates that the correct sign (+ or -) should always be printed.-
: Currently not used
Sourcepub fn sign_aware_zero_pad(&mut self, sign_aware_zero_pad: bool) -> &mut Self
π¬This is a nightly-only experimental API. (formatting_options
#118117)
pub fn sign_aware_zero_pad(&mut self, sign_aware_zero_pad: bool) -> &mut Self
formatting_options
#118117)Sets or unsets the 0
flag.
This is used to indicate for integer formats that the padding to width should both be done with a 0 character as well as be sign-aware
Sourcepub fn alternate(&mut self, alternate: bool) -> &mut Self
π¬This is a nightly-only experimental API. (formatting_options
#118117)
pub fn alternate(&mut self, alternate: bool) -> &mut Self
formatting_options
#118117)Sets or unsets the #
flag.
This flag indicates that the βalternateβ form of printing should be used. The alternate forms are:
Sourcepub fn fill(&mut self, fill: char) -> &mut Self
π¬This is a nightly-only experimental API. (formatting_options
#118117)
pub fn fill(&mut self, fill: char) -> &mut Self
formatting_options
#118117)Sets the fill character.
The optional fill character and alignment is provided normally in conjunction with the width parameter. This indicates that if the value being formatted is smaller than width some extra characters will be printed around it.
Sourcepub fn align(&mut self, align: Option<Alignment>) -> &mut Self
π¬This is a nightly-only experimental API. (formatting_options
#118117)
pub fn align(&mut self, align: Option<Alignment>) -> &mut Self
formatting_options
#118117)Sets or removes the alignment.
The alignment specifies how the value being formatted should be positioned if it is smaller than the width of the formatter.
Sourcepub fn width(&mut self, width: Option<u16>) -> &mut Self
π¬This is a nightly-only experimental API. (formatting_options
#118117)
pub fn width(&mut self, width: Option<u16>) -> &mut Self
formatting_options
#118117)Sets or removes the width.
This is a parameter for the βminimum widthβ that the format should take
up. If the valueβs string does not fill up this many characters, then
the padding specified by FormattingOptions::fill
/FormattingOptions::align
will be used to take up the required space.
Sourcepub fn precision(&mut self, precision: Option<u16>) -> &mut Self
π¬This is a nightly-only experimental API. (formatting_options
#118117)
pub fn precision(&mut self, precision: Option<u16>) -> &mut Self
formatting_options
#118117)Sets or removes the precision.
- For non-numeric types, this can be considered a βmaximum widthβ. If the resulting string is longer than this width, then it is truncated down to this many characters and that truncated value is emitted with proper fill, alignment and width if those parameters are set.
- For integral types, this is ignored.
- For floating-point types, this indicates how many digits after the decimal point should be printed.
Sourcepub fn debug_as_hex(&mut self, debug_as_hex: Option<DebugAsHex>) -> &mut Self
π¬This is a nightly-only experimental API. (formatting_options
#118117)
pub fn debug_as_hex(&mut self, debug_as_hex: Option<DebugAsHex>) -> &mut Self
formatting_options
#118117)Specifies whether the Debug
trait should use lower-/upper-case
hexadecimal or normal integers
Sourcepub const fn get_sign(&self) -> Option<Sign>
π¬This is a nightly-only experimental API. (formatting_options
#118117)
pub const fn get_sign(&self) -> Option<Sign>
formatting_options
#118117)Returns the current sign (the +
or the -
flag).
Sourcepub const fn get_sign_aware_zero_pad(&self) -> bool
π¬This is a nightly-only experimental API. (formatting_options
#118117)
pub const fn get_sign_aware_zero_pad(&self) -> bool
formatting_options
#118117)Returns the current 0
flag.
Sourcepub const fn get_alternate(&self) -> bool
π¬This is a nightly-only experimental API. (formatting_options
#118117)
pub const fn get_alternate(&self) -> bool
formatting_options
#118117)Returns the current #
flag.
Sourcepub const fn get_fill(&self) -> char
π¬This is a nightly-only experimental API. (formatting_options
#118117)
pub const fn get_fill(&self) -> char
formatting_options
#118117)Returns the current fill character.
Sourcepub const fn get_align(&self) -> Option<Alignment>
π¬This is a nightly-only experimental API. (formatting_options
#118117)
pub const fn get_align(&self) -> Option<Alignment>
formatting_options
#118117)Returns the current alignment.
Sourcepub const fn get_width(&self) -> Option<u16>
π¬This is a nightly-only experimental API. (formatting_options
#118117)
pub const fn get_width(&self) -> Option<u16>
formatting_options
#118117)Returns the current width.
Sourcepub const fn get_precision(&self) -> Option<u16>
π¬This is a nightly-only experimental API. (formatting_options
#118117)
pub const fn get_precision(&self) -> Option<u16>
formatting_options
#118117)Returns the current precision.
Sourcepub const fn get_debug_as_hex(&self) -> Option<DebugAsHex>
π¬This is a nightly-only experimental API. (formatting_options
#118117)
pub const fn get_debug_as_hex(&self) -> Option<DebugAsHex>
formatting_options
#118117)Returns the current precision.
Sourcepub fn create_formatter<'a>(
self,
write: &'a mut (dyn Write + 'a),
) -> Formatter<'a>
π¬This is a nightly-only experimental API. (formatting_options
#118117)
pub fn create_formatter<'a>( self, write: &'a mut (dyn Write + 'a), ) -> Formatter<'a>
formatting_options
#118117)Creates a Formatter
that writes its output to the given Write
trait.
You may alternatively use Formatter::new()
.
Trait ImplementationsΒ§
SourceΒ§impl Clone for FormattingOptions
impl Clone for FormattingOptions
SourceΒ§fn clone(&self) -> FormattingOptions
fn clone(&self) -> FormattingOptions
1.0.0 Β· SourceΒ§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSourceΒ§impl Debug for FormattingOptions
impl Debug for FormattingOptions
SourceΒ§impl Default for FormattingOptions
impl Default for FormattingOptions
SourceΒ§fn default() -> Self
fn default() -> Self
Same as FormattingOptions::new()
.
SourceΒ§impl Eq for FormattingOptions
impl Eq for FormattingOptions
#[doc(hidden)] fn assert_receiver_is_total_eq(&self)
SourceΒ§impl PartialEq for FormattingOptions
impl PartialEq for FormattingOptions
impl Copy for FormattingOptions
impl StructuralPartialEq for FormattingOptions
Auto Trait ImplementationsΒ§
impl Freeze for FormattingOptions
impl RefUnwindSafe for FormattingOptions
impl Send for FormattingOptions
impl Sync for FormattingOptions
impl Unpin for FormattingOptions
impl UnsafeUnpin for FormattingOptions
impl UnwindSafe for FormattingOptions
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Β§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
SourceΒ§#[doc(hidden)] const IS_ZST: bool = _
#[doc(hidden)] const IS_ZST: bool = _
sized_type_properties
)SourceΒ§#[doc(hidden)] const LAYOUT: Layout = _
#[doc(hidden)] const LAYOUT: Layout = _
sized_type_properties
)SourceΒ§#[doc(hidden)] const MAX_SLICE_LEN: usize = _
#[doc(hidden)] const MAX_SLICE_LEN: usize = _
sized_type_properties
)[Self]
. Read more