]> git.lizzy.rs Git - rust.git/commitdiff
Clarify std::fmt width docs w.r.t. dollar syntax and give example.
authorGeorg Brandl <georg@python.org>
Thu, 28 Apr 2016 15:49:10 +0000 (17:49 +0200)
committerGeorg Brandl <georg@python.org>
Thu, 28 Apr 2016 15:50:12 +0000 (17:50 +0200)
src/libcollections/fmt.rs

index e30e0b213afa161eb3da80c251349bd90af865f7..710a30ff2364ecdbdd076b40ac0b0c2da0f2fb9b 100644 (file)
 //! `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
 //!