- Rust Standard Library Cookbook
- Jan Nils Ferner Daniel Durante
- 188字
- 2021-08-27 19:45:02
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!
- DSP原理及應(yīng)用:TMS320DM6437架構(gòu)、指令、功能模塊、程序設(shè)計及案例分析
- 教你看懂CRT數(shù)字高清彩色電視機線路圖
- 電子技術(shù)進階500問
- 機載激光雷達基礎(chǔ)原理與應(yīng)用
- RFID 重大工程與國家物聯(lián)網(wǎng)(第3版)
- 零起點學(xué)音響與影碟機維修技術(shù)
- Identity with Windows Server 2016:Microsoft 70-742 MCSA Exam Guide
- 電子設(shè)備人機工程設(shè)計及應(yīng)用
- 手機故障維修技巧與實例
- 5G大規(guī)模天線增強技術(shù)
- LTE教程:原理與實現(xiàn)(第3版)
- 實戰(zhàn)無線通信應(yīng)知應(yīng)會:新手入門,老手溫故(第二版)
- 移動通信原理、技術(shù)與系統(tǒng)
- 電子元器件從入門到精通(全2冊)
- 電子對抗英漢、漢英、縮略語詞典