Skip to content

Commit 33cc71a

Browse files
authored
Rollup merge of rust-lang#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 `#`
2 parents 7cf4405 + 9e415d1 commit 33cc71a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

alloc/src/fmt.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
//! format!("{value}", value=4); // => "4"
2020
//! format!("{} {}", 1, 2); // => "1 2"
2121
//! format!("{:04}", 42); // => "0042" with leading zeros
22+
//! format!("{:#?}", (100, 200)); // => "(
23+
//! // 100,
24+
//! // 200,
25+
//! // )"
2226
//! ```
2327
//!
2428
//! From these, you can see that the first argument is a format string. It is
@@ -163,7 +167,7 @@
163167
//! * `-` - Currently not used
164168
//! * `#` - This flag indicates that the "alternate" form of printing should
165169
//! be used. The alternate forms are:
166-
//! * `#?` - pretty-print the [`Debug`] formatting
170+
//! * `#?` - pretty-print the [`Debug`] formatting (adds linebreaks and indentation)
167171
//! * `#x` - precedes the argument with a `0x`
168172
//! * `#X` - precedes the argument with a `0x`
169173
//! * `#b` - precedes the argument with a `0b`

0 commit comments

Comments
 (0)