小编Fre*_*red的帖子

Rust格式字符串中的美元语法是什么意思?

我将通过示例进行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)

string-formatting rust

7
推荐指数
1
解决办法
637
查看次数

标签 统计

rust ×1

string-formatting ×1