about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2016-04-28 20:18:39 +0200
committerGeorg Brandl <georg@python.org>2016-04-29 21:17:22 +0200
commit84bd1ce9841dbefc30c2ade67964ac652856e8a3 (patch)
treedc0c1b5ad271633e1ae158bd6d724013cd4b3fb5
parente07e34c4b0ccdc0feecd49091682e6cc365b279a (diff)
downloadrust-84bd1ce9841dbefc30c2ade67964ac652856e8a3.tar.gz
rust-84bd1ce9841dbefc30c2ade67964ac652856e8a3.zip
Fix std::fmt format spec: named args are allowed with "$" syntax
-rw-r--r--src/libcollections/fmt.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/libcollections/fmt.rs b/src/libcollections/fmt.rs
index 710a30ff236..d58c26a7213 100644
--- a/src/libcollections/fmt.rs
+++ b/src/libcollections/fmt.rs
@@ -333,7 +333,7 @@
 //! precision := count | '*'
 //! type := identifier | ''
 //! count := parameter | integer
-//! parameter := integer '$'
+//! parameter := argument '$'
 //! ```
 //!
 //! # Formatting Parameters
@@ -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
 //!
@@ -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.
 //!
@@ -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: