Skip to content

Commit

Permalink
Auto merge of #33277 - birkenfeld:fmt-named-dollar-args, r=steveklabnik
Browse files Browse the repository at this point in the history
Fix std::fmt format spec: named args are allowed with "$" syntax
  • Loading branch information
bors committed Apr 30, 2016
2 parents 2a815a2 + 84bd1ce commit daf281d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/libcollections/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
//! precision := count | '*'
//! type := identifier | ''
//! count := parameter | integer
//! parameter := integer '$'
//! parameter := argument '$'
//! ```
//!
//! # Formatting Parameters
Expand Down Expand Up @@ -403,11 +403,12 @@
//! println!("Hello {:5}!", "x");
//! println!("Hello {:1$}!", "x", 5);
//! println!("Hello {1:0$}!", 5, "x");
//! println!("Hello {:width$}!", "x", width = 5);
//! ```
//!
//! 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.
//! argument" counter, so it's usually a good idea to refer to arguments by
//! position, or use named arguments.
//!
//! ## Precision
//!
Expand All @@ -426,7 +427,7 @@
//!
//! the integer `N` itself is the precision.
//!
//! 2. An integer followed by dollar sign `.N$`:
//! 2. An integer or name followed by dollar sign `.N$`:
//!
//! use format *argument* `N` (which must be a `usize`) as the precision.
//!
Expand Down Expand Up @@ -456,6 +457,10 @@
//! // Hello {next arg (x)} is {arg 2 (0.01) with precision
//! // specified in its predecessor (5)}
//! println!("Hello {} is {2:.*}", "x", 5, 0.01);
//!
//! // Hello {next arg (x)} is {arg "number" (0.01) with precision specified
//! // in arg "prec" (5)}
//! println!("Hello {} is {number:.prec$}", "x", prec = 5, number = 0.01);
//! ```
//!
//! All print the same thing:
Expand Down

0 comments on commit daf281d

Please sign in to comment.