Skip to content

Commit

Permalink
Rollup merge of #33258 - birkenfeld:fmt-dollar-syntax, r=brson
Browse files Browse the repository at this point in the history
Clarify std::fmt width docs w.r.t. dollar syntax and give example.

The previous version only said "the `2$` syntax", which while introduced in the grammar is not very self-explanatory.
  • Loading branch information
Manishearth committed Apr 29, 2016
2 parents 3a0efff + 815987b commit f30058f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/libcollections/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,19 @@
//! `0`.
//!
//! The value for the width can also be provided as a `usize` in the list of
//! parameters by using the `2$` syntax indicating that the second argument is a
//! `usize` specifying the width.
//! parameters by using the dollar syntax indicating that the second argument is
//! a `usize` specifying the width, for example:
//!
//! ```
//! // All of these print "Hello x !"
//! println!("Hello {:5}!", "x");
//! println!("Hello {:1$}!", "x", 5);
//! println!("Hello {1:0$}!", 5, "x");
//! ```
//!
//! Referring to an argument with the dollar syntax does not affect the "next
//! argument" counter, so it's usually a good idea to refer to all arguments by
//! their position explicitly.
//!
//! ## Precision
//!
Expand Down

0 comments on commit f30058f

Please sign in to comment.