Struct FormattingOptions

struct FormattingOptions { ... }

Options for formatting.

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

Implementations

impl FormattingOptions

const fn new() -> Self

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.
const fn sign(self: &mut Self, sign: Option<Sign>) -> &mut Self

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
const fn sign_aware_zero_pad(self: &mut Self, sign_aware_zero_pad: bool) -> &mut Self

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

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

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 0o
  • Binary - precedes the argument with a 0b
const fn fill(self: &mut Self, fill: char) -> &mut Self

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.

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

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.

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

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.

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

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.
const fn debug_as_hex(self: &mut Self, debug_as_hex: Option<DebugAsHex>) -> &mut Self

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

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

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

const fn get_sign_aware_zero_pad(self: &Self) -> bool

Returns the current 0 flag.

const fn get_alternate(self: &Self) -> bool

Returns the current # flag.

const fn get_fill(self: &Self) -> char

Returns the current fill character.

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

Returns the current alignment.

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

Returns the current width.

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

Returns the current precision.

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

Returns the current precision.

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

Creates a Formatter that writes its output to the given Write trait.

You may alternatively use [Formatter::new()].

impl Clone for FormattingOptions

fn clone(self: &Self) -> FormattingOptions

impl Copy for FormattingOptions

impl Debug for FormattingOptions

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

impl Default for FormattingOptions

fn default() -> Self

Same as [FormattingOptions::new()].

impl Eq for FormattingOptions

impl Freeze for FormattingOptions

impl PartialEq for FormattingOptions

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

impl RefUnwindSafe for FormattingOptions

impl Send for FormattingOptions

impl StructuralPartialEq for FormattingOptions

impl Sync for FormattingOptions

impl Unpin for FormattingOptions

impl UnwindSafe for FormattingOptions

impl<T> Any for FormattingOptions

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for FormattingOptions

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for FormattingOptions

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

impl<T> CloneToUninit for FormattingOptions

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

impl<T> From for FormattingOptions

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for FormattingOptions

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for FormattingOptions

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for FormattingOptions

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>