std-type

Formatter: inspect requested options

Formatting implementations receive the formatter from the caller. The width, precision and alignment are requested options, not automatically enforced by arbitrary custom implementations. Expected stdout (not executed): | ready| Common mistake: Using write_str alone and expecting automatic padding.

Formal Syntax & Structure

rust syntaxrust
&mut std::fmt::Formatter<'_>

Working Example

Example Snippetrust
fn main() {    use std::fmt;    struct Label;    impl fmt::Display for Label {        fn fmt(&self,f:&mut fmt::Formatter<'_>)->fmt::Result { f.pad("ready") }    }    println!("|{:>8}|", Label);}
Rust Reference