Struct FormattingOptions

Source
pub struct FormattingOptions {
    flags: u32,
    width: u16,
    precision: u16,
}
πŸ”¬This is a nightly-only experimental API. (formatting_options #118117)
Expand description

Options for formatting.

FormattingOptions is a Formatter without an attached Write trait. It is mainly used to construct Formatter instances.

FieldsΒ§

Β§flags: u32
πŸ”¬This is a nightly-only experimental API. (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
πŸ”¬This is a nightly-only experimental API. (formatting_options #118117)

Width if width flag (bit 27) above is set. Otherwise, always 0.

Β§precision: u16
πŸ”¬This is a nightly-only experimental API. (formatting_options #118117)

Precision if precision flag (bit 28) above is set. Otherwise, always 0.

ImplementationsΒ§

SourceΒ§

impl FormattingOptions

Source

pub const fn new() -> Self

πŸ”¬This is a nightly-only experimental API. (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.
Source

pub fn sign(&mut self, sign: Option<Sign>) -> &mut Self

πŸ”¬This is a nightly-only experimental API. (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
Source

pub fn sign_aware_zero_pad(&mut self, sign_aware_zero_pad: bool) -> &mut Self

πŸ”¬This is a nightly-only experimental API. (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

Source

pub fn alternate(&mut self, alternate: bool) -> &mut Self

πŸ”¬This is a nightly-only experimental API. (formatting_options #118117)

Sets or unsets the # flag.

This flag indicates that the β€œalternate” form of printing should be used. The alternate forms are:

  • Debug : pretty-print the Debug formatting (adds linebreaks and indentation)
  • LowerHex as well as UpperHex - precedes the argument with a 0x
  • Octal - precedes the argument with a 0b
  • Binary - precedes the argument with a 0o
Source

pub fn fill(&mut self, fill: char) -> &mut Self

πŸ”¬This is a nightly-only experimental API. (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.

Source

pub fn align(&mut self, align: Option<Alignment>) -> &mut Self

πŸ”¬This is a nightly-only experimental API. (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.

Source

pub fn width(&mut self, width: Option<u16>) -> &mut Self

πŸ”¬This is a nightly-only experimental API. (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.

Source

pub fn precision(&mut self, precision: Option<u16>) -> &mut Self

πŸ”¬This is a nightly-only experimental API. (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.
Source

pub fn debug_as_hex(&mut self, debug_as_hex: Option<DebugAsHex>) -> &mut Self

πŸ”¬This is a nightly-only experimental API. (formatting_options #118117)

Specifies whether the Debug trait should use lower-/upper-case hexadecimal or normal integers

Source

pub const fn get_sign(&self) -> Option<Sign>

πŸ”¬This is a nightly-only experimental API. (formatting_options #118117)

Returns the current sign (the + or the - flag).

Source

pub const fn get_sign_aware_zero_pad(&self) -> bool

πŸ”¬This is a nightly-only experimental API. (formatting_options #118117)

Returns the current 0 flag.

Source

pub const fn get_alternate(&self) -> bool

πŸ”¬This is a nightly-only experimental API. (formatting_options #118117)

Returns the current # flag.

Source

pub const fn get_fill(&self) -> char

πŸ”¬This is a nightly-only experimental API. (formatting_options #118117)

Returns the current fill character.

Source

pub const fn get_align(&self) -> Option<Alignment>

πŸ”¬This is a nightly-only experimental API. (formatting_options #118117)

Returns the current alignment.

Source

pub const fn get_width(&self) -> Option<u16>

πŸ”¬This is a nightly-only experimental API. (formatting_options #118117)

Returns the current width.

Source

pub const fn get_precision(&self) -> Option<u16>

πŸ”¬This is a nightly-only experimental API. (formatting_options #118117)

Returns the current precision.

Source

pub const fn get_debug_as_hex(&self) -> Option<DebugAsHex>

πŸ”¬This is a nightly-only experimental API. (formatting_options #118117)

Returns the current precision.

Source

pub fn create_formatter<'a>( self, write: &'a mut (dyn Write + 'a), ) -> Formatter<'a>

πŸ”¬This is a nightly-only experimental API. (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

SourceΒ§

fn clone(&self) -> FormattingOptions

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 FormattingOptions

SourceΒ§

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

Formats the value using the given formatter. Read more
SourceΒ§

impl Default for FormattingOptions

SourceΒ§

impl Eq for FormattingOptions

SourceΒ§

#[doc(hidden)] fn assert_receiver_is_total_eq(&self)

SourceΒ§

impl PartialEq for FormattingOptions

SourceΒ§

fn eq(&self, other: &FormattingOptions) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 Β· SourceΒ§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
SourceΒ§

impl Copy for FormattingOptions

SourceΒ§

impl StructuralPartialEq for FormattingOptions

Auto Trait ImplementationsΒ§

Blanket ImplementationsΒ§

SourceΒ§

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

SourceΒ§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
SourceΒ§

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

SourceΒ§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
SourceΒ§

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

SourceΒ§

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

Mutably borrows from an owned value. Read more
SourceΒ§

impl<T> CloneToUninit for T
where T: Clone,

SourceΒ§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

πŸ”¬This is a nightly-only experimental API. (clone_to_uninit #126799)
Performs copy-assignment from self to dest. 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 T
where 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> SizedTypeProperties for T

SourceΒ§

#[doc(hidden)] const IS_ZST: bool = _

πŸ”¬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
SourceΒ§

#[doc(hidden)] const LAYOUT: Layout = _

πŸ”¬This is a nightly-only experimental API. (sized_type_properties)
SourceΒ§

#[doc(hidden)] const MAX_SLICE_LEN: usize = _

πŸ”¬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. Read more
SourceΒ§

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

SourceΒ§

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 T
where U: TryFrom<T>,

SourceΒ§

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.
SourceΒ§

impl<T> NonDrop for T
where T: Copy,

SourceΒ§

impl<T> Printable for T
where T: Copy + Debug,