Rollup merge of #83388 - alamb:alamb/fmt-dcs, r=Mark-Simulacrum
Make # pretty print format easier to discover # Rationale: I use (cargo cult?) three formats in rust: `{}`, debug `{:?}`, and pretty-print debug `{:#?}`. I discovered `{:#?}` in some blog post or guide when I started working in Rust. While `#` is documented I think it is hard to discover. So taking the good advice of ```@carols10cents``` I am trying to improve the docs with a PR As a reminder "pretty print" means that where `{:?}` will print something like ``` foo: { b1: 1, b2: 2} ``` `{:#?}` will prints something like ``` foo { b1: 1 b2: 3 } ``` # Changes Add an example to `fmt` to try and make it easier to discover `#`
This commit is contained in:
commit
c143267901
1 changed files with 5 additions and 1 deletions
|
@ -19,6 +19,10 @@
|
||||||
//! format!("{value}", value=4); // => "4"
|
//! format!("{value}", value=4); // => "4"
|
||||||
//! format!("{} {}", 1, 2); // => "1 2"
|
//! format!("{} {}", 1, 2); // => "1 2"
|
||||||
//! format!("{:04}", 42); // => "0042" with leading zeros
|
//! format!("{:04}", 42); // => "0042" with leading zeros
|
||||||
|
//! format!("{:#?}", (100, 200)); // => "(
|
||||||
|
//! // 100,
|
||||||
|
//! // 200,
|
||||||
|
//! // )"
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! From these, you can see that the first argument is a format string. It is
|
//! From these, you can see that the first argument is a format string. It is
|
||||||
|
@ -163,7 +167,7 @@
|
||||||
//! * `-` - Currently not used
|
//! * `-` - Currently not used
|
||||||
//! * `#` - This flag indicates that the "alternate" form of printing should
|
//! * `#` - This flag indicates that the "alternate" form of printing should
|
||||||
//! be used. The alternate forms are:
|
//! be used. The alternate forms are:
|
||||||
//! * `#?` - pretty-print the [`Debug`] formatting
|
//! * `#?` - pretty-print the [`Debug`] formatting (adds linebreaks and indentation)
|
||||||
//! * `#x` - precedes the argument with a `0x`
|
//! * `#x` - precedes the argument with a `0x`
|
||||||
//! * `#X` - precedes the argument with a `0x`
|
//! * `#X` - precedes the argument with a `0x`
|
||||||
//! * `#b` - precedes the argument with a `0b`
|
//! * `#b` - precedes the argument with a `0b`
|
||||||
|
|
Loading…
Reference in a new issue