官术网_书友最值得收藏!

There's more...

You can combine positional parameters with normal ones, but it's probably not a good idea, as it can quite easily become confusing to look at. The behavior, in this case, is as follows—imagine that format! internally uses a counter to determine which argument is the next to be placed. This counter is increased whenever format! encounters a {} without a position in it. This rule results in the following:

format!("{1} {} {0} {}", "a", "b") // Returns "b a a b"

There are also a ton of extra formatting options if you want to display your data in different formats. {:?} prints the implementation of the Debug trait for the respective argument, often resulting in a more verbose output. {:.*} lets you specify the decimal precision of floating point numbers via the argument, like so:

format!("{:.*}", 2, 1.234567) // Returns "1.23"

For a complete list, visit https://doc.rust-lang.org/std/fmt/.

All of the information in this recipe applies to println! and print! as well, as it is essentially the same macro. The only difference is that println! doesn't return its processed string but instead, well, prints it!

主站蜘蛛池模板: 鹰潭市| 连江县| 如东县| 宜兴市| 肃南| 海淀区| 永济市| 晋江市| 方城县| 淄博市| 深州市| 阿克陶县| 同仁县| 浙江省| 县级市| 和平县| 滨州市| 壤塘县| 太保市| 库车县| 察隅县| 沐川县| 呼和浩特市| 兴文县| 高雄县| 东丰县| 达日县| 樟树市| 屏东市| 漳州市| 太谷县| 永州市| 南投县| 金湖县| 肥西县| 丹寨县| 顺平县| 渭源县| 宣威市| 沙河市| 兴和县|