std::fmt::Formatter - Rust (original) (raw)

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.

`pub fn pad_integral(

&mut self,
is_nonnegative: bool,
prefix: &str,
buf: &str
) -> Result<(), Error>`[src]

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

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

pub fn [pad](#method.pad)(&mut self, s: &[str](../primitive.str.html)) -> [Result](../../std/result/enum.Result.html "enum std::result::Result")<[()](../primitive.unit.html), [Error](../../std/fmt/struct.Error.html "struct std::fmt::Error")>[src]

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:

Notably this function ignores the flag parameters.

pub fn [write_str](#method.write%5Fstr)(&mut self, data: &[str](../primitive.str.html)) -> [Result](../../std/result/enum.Result.html "enum std::result::Result")<[()](../primitive.unit.html), [Error](../../std/fmt/struct.Error.html "struct std::fmt::Error")>[src]

Writes some data to the underlying buffer contained within this formatter.

pub fn [write_fmt](#method.write%5Ffmt)(&mut self, fmt: [Arguments](../../std/fmt/struct.Arguments.html "struct std::fmt::Arguments")) -> [Result](../../std/result/enum.Result.html "enum std::result::Result")<[()](../primitive.unit.html), [Error](../../std/fmt/struct.Error.html "struct std::fmt::Error")>[src]

Writes some formatted information into this instance

pub fn [flags](#method.flags)(&self) -> [u32](../primitive.u32.html)[src]

Deprecated since 1.24.0

: use the sign_plus, sign_minus, alternate, or sign_aware_zero_pad methods instead

Flags for formatting

pub fn [fill](#method.fill)(&self) -> [char](../primitive.char.html)

1.5.0

[src]

Character used as 'fill' whenever there is alignment

pub fn [align](#method.align)(&self) -> [Alignment](../../core/fmt/enum.Alignment.html "enum core::fmt::Alignment")[src]

🔬 This is a nightly-only experimental API. (fmt_flags_align #27726)

method was just created

Flag indicating what form of alignment was requested

pub fn [width](#method.width)(&self) -> [Option](../../std/option/enum.Option.html "enum std::option::Option")<[usize](../primitive.usize.html)>

1.5.0

[src]

Optionally specified integer width that the output should be

pub fn [precision](#method.precision)(&self) -> [Option](../../std/option/enum.Option.html "enum std::option::Option")<[usize](../primitive.usize.html)>

1.5.0

[src]

Optionally specified precision for numeric types

pub fn [sign_plus](#method.sign%5Fplus)(&self) -> [bool](../primitive.bool.html)

1.5.0

[src]

Determines if the + flag was specified.

pub fn [sign_minus](#method.sign%5Fminus)(&self) -> [bool](../primitive.bool.html)

1.5.0

[src]

Determines if the - flag was specified.

pub fn [alternate](#method.alternate)(&self) -> [bool](../primitive.bool.html)

1.5.0

[src]

Determines if the # flag was specified.

pub fn [sign_aware_zero_pad](#method.sign%5Faware%5Fzero%5Fpad)(&self) -> [bool](../primitive.bool.html)

1.5.0

[src]

Determines if the 0 flag was specified.

pub fn [debug_struct](#method.debug%5Fstruct)(&'b mut self, name: &[str](../primitive.str.html)) -> [DebugStruct](../../std/fmt/struct.DebugStruct.html "struct std::fmt::DebugStruct")<'b, 'a>

1.2.0

[src]

Creates a DebugStruct builder designed to assist with creation offmt::Debug implementations for structs.

use std::fmt;

struct Foo { bar: i32, baz: String, }

impl fmt::Debug for Foo { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_struct("Foo") .field("bar", &self.bar) .field("baz", &self.baz) .finish() } }

println!("{:?}", Foo { bar: 10, baz: "Hello World".to_string() });Run

pub fn [debug_tuple](#method.debug%5Ftuple)(&'b mut self, name: &[str](../primitive.str.html)) -> [DebugTuple](../../std/fmt/struct.DebugTuple.html "struct std::fmt::DebugTuple")<'b, 'a>

1.2.0

[src]

Creates a DebugTuple builder designed to assist with creation offmt::Debug implementations for tuple structs.

use std::fmt;

struct Foo(i32, String);

impl fmt::Debug for Foo { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_tuple("Foo") .field(&self.0) .field(&self.1) .finish() } }

println!("{:?}", Foo(10, "Hello World".to_string()));Run

pub fn [debug_list](#method.debug%5Flist)(&'b mut self) -> [DebugList](../../std/fmt/struct.DebugList.html "struct std::fmt::DebugList")<'b, 'a>

1.2.0

[src]

Creates a DebugList builder designed to assist with creation offmt::Debug implementations for list-like structures.

use std::fmt;

struct Foo(Vec);

impl fmt::Debug for Foo { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_list().entries(self.0.iter()).finish() } }

println!("{:?}", Foo(vec![10, 11]));Run

pub fn [debug_set](#method.debug%5Fset)(&'b mut self) -> [DebugSet](../../std/fmt/struct.DebugSet.html "struct std::fmt::DebugSet")<'b, 'a>

1.2.0

[src]

Creates a DebugSet builder designed to assist with creation offmt::Debug implementations for set-like structures.

use std::fmt;

struct Foo(Vec);

impl fmt::Debug for Foo { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_set().entries(self.0.iter()).finish() } }

println!("{:?}", Foo(vec![10, 11]));Run

pub fn [debug_map](#method.debug%5Fmap)(&'b mut self) -> [DebugMap](../../std/fmt/struct.DebugMap.html "struct std::fmt::DebugMap")<'b, 'a>

1.2.0

[src]

Creates a DebugMap builder designed to assist with creation offmt::Debug implementations for map-like structures.

use std::fmt;

struct Foo(Vec<(String, i32)>);

impl fmt::Debug for Foo { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_map().entries(self.0.iter().map(|&(ref k, ref v)| (k, v))).finish() } }

println!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)]));Run