Struct FormattingOptions
pub struct FormattingOptions { pub(in ::fmt) flags: u32, pub(in ::fmt) width: u16, pub(in ::fmt) precision: u16 }
Options for formatting.
FormattingOptions is a Formatter without an attached Write trait.
It is mainly used to construct Formatter instances.
Fields
flags: u32Flags, with the following bit fields:
31 30 29 28 27 26 25 24 23 22 21 20 0 ┌───┬───────┬───┬───┬───┬───┬───┬───┬───┬───┬──────────────────────────────────┐ │ 0 │ 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 zero.width: u16Width if width flag (bit 27) above is set. Otherwise, always 0.
precision: u16Precision if precision flag (bit 28) above is set. Otherwise, always 0.
Implementations
impl FormattingOptions
const fn new() -> SelfConstruct a new
FormattingOptionsrepresenting the plain{}formatting specifier:- no flags,
- filled with spaces,
- no alignment,
- no width,
- no precision, and
- no
DebugAsHexoutput mode.
const fn sign(&mut self, sign: Option<Sign>) -> &mut SelfSets 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
const fn sign_aware_zero_pad(&mut self, sign_aware_zero_pad: bool) -> &mut SelfSets or unsets the
0flag.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
const fn alternate(&mut self, alternate: bool) -> &mut SelfSets or unsets the
#flag.This flag indicates that the "alternate" form of printing should be used. The alternate forms are:
const fn fill(&mut self, fill: char) -> &mut SelfSets 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.
const fn align(&mut self, align: Option<Alignment>) -> &mut SelfSets 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.
const fn width(&mut self, width: Option<u16>) -> &mut SelfSets 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::alignwill be used to take up the required space.const fn precision(&mut self, precision: Option<u16>) -> &mut SelfSets 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.
const fn debug_as_hex(&mut self, debug_as_hex: Option<DebugAsHex>) -> &mut SelfSpecifies whether the
Debugtrait should use lower-/upper-case hexadecimal or normal integersconst fn get_sign(&self) -> Option<Sign>Returns the current sign (the
+or the-flag).const fn get_sign_aware_zero_pad(&self) -> boolReturns the current
0flag.const fn get_alternate(&self) -> boolReturns the current
#flag.const fn get_fill(&self) -> charReturns the current fill character.
const fn get_align(&self) -> Option<Alignment>Returns the current alignment.
const fn get_width(&self) -> Option<u16>Returns the current width.
const fn get_precision(&self) -> Option<u16>Returns the current precision.
const fn get_debug_as_hex(&self) -> Option<DebugAsHex>Returns the current
x?orX?flag.const fn create_formatter<'a>(self, write: &'a mut dyn Write + 'a) -> Formatter<'a>Creates a
Formatterthat writes its output to the givenWritetrait.You may alternatively use [
Formatter::new()].
Trait Implementations
impl Clone for FormattingOptions
fn clone(&self) -> FormattingOptions
impl Copy for FormattingOptions
impl Debug for FormattingOptions
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Default for FormattingOptions
fn default() -> SelfSame as [
FormattingOptions::new()].
impl Eq for FormattingOptions
fn assert_fields_are_eq(&self)
impl PartialEq for FormattingOptions
fn eq(&self, other: &FormattingOptions) -> bool
impl StructuralPartialEq for FormattingOptions
impl TrivialClone 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
impl<T> Any for FormattingOptions
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for FormattingOptions
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for FormattingOptions
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for FormattingOptions
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for FormattingOptions
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Printable for FormattingOptions
where
T: Copy + Debug,
impl<T> SizeHint for FormattingOptions
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for FormattingOptions
impl<T, U> Into<U> for FormattingOptions
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for FormattingOptions
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for FormattingOptions
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>