diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2016-04-29 16:03:32 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2016-04-29 19:17:59 +0530 |
| commit | f30058facff3c60e3d9c8fd22b40aae10bb8e022 (patch) | |
| tree | d2543fc9a925d84c0d85368971bcfc3bbd0185fd /src | |
| parent | 3a0efffc9dd2df5b55ee0e111875a018aaa4ecf9 (diff) | |
| parent | 815987b4ce9c1649133263b388903322dd77ea6c (diff) | |
| download | rust-f30058facff3c60e3d9c8fd22b40aae10bb8e022.tar.gz rust-f30058facff3c60e3d9c8fd22b40aae10bb8e022.zip | |
Rollup merge of #33258 - birkenfeld:fmt-dollar-syntax, r=brson
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcollections/fmt.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/libcollections/fmt.rs b/src/libcollections/fmt.rs index e30e0b213af..710a30ff236 100644 --- a/src/libcollections/fmt.rs +++ b/src/libcollections/fmt.rs @@ -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 //! |
