我将通过示例进行Rust,在这个示例中使用$(美元符号)对我来说并不清楚:
// You can right-align text with a specified width. This will output
// " 1". 5 white spaces and a "1".
println!("{number:>width$}", number=1, width=6);
// You can pad numbers with extra zeroes. This will output "000001".
println!("{number:>0width$}", number=1, width=6);
Run Code Online (Sandbox Code Playgroud)
我在文档中std::fmt找到了这个,但它没有为我澄清一些事情:
format_string := <text> [ maybe-format <text> ] *
maybe-format := '{' '{' | '}' '}' | <format>
format := '{' [ argument ] [ ':' format_spec ] '}'
argument := integer | …Run Code Online (Sandbox Code Playgroud)