[src]

Struct std::fmt::Formatter

pub struct Formatter<'a> {
    flags: uint,
    fill: char,
    align: Alignment,
    width: Option<uint>,
    precision: Option<uint>,
    buf: &'a mut Writer,
    // some fields omitted
}

A struct to represent both where to emit formatting strings to and how they should be formatted. A mutable version of this is passed to all formatting traits.

Fields

flags

Flags for formatting (packed version of rt::Flag)

fill

Character used as 'fill' whenever there is alignment

align

Boolean indication of whether the output should be left-aligned

width

Optionally specified integer width that the output should be

precision

Optionally specified precision for numeric types

buf

Output buffer.

Methods

impl<'a> Formatter<'a>

fn pad_integral(&mut self, is_positive: bool, prefix: &str, buf: &[u8]) -> Result

Performs the correct padding for an integer which has already been emitted into a byte-array. The byte-array should not contain the sign for the integer, that will be added by this method.

Arguments

  • is_positive - whether the original integer was positive or not.
  • prefix - if the '#' character (FlagAlternate) is provided, this is the prefix to put in front of the number.
  • buf - the byte array that the number has been formatted into

This function will correctly account for the flags provided as well as the minimum width. It will not take precision into account.

fn pad(&mut self, s: &str) -> Result

This function takes a string slice and emits it to the internal buffer after applying the relevant formatting flags specified. The flags recognized for generic strings are:

  • width - the minimum width of what to emit
  • fill/align - what to emit and where to emit it if the string provided needs to be padded
  • precision - the maximum length to emit, the string is truncated if it is longer than this length

Notably this function ignored the flag parameters