|
81 | 81 | //!
|
82 | 82 | //! ```
|
83 | 83 | //! format!("{argument}", argument = "test"); // => "test"
|
84 |
| -//! format!("{name} {}", 1, name = 2); // => "2 1" |
| 84 | +//! format!("{name} {}", 1, name = 2); // => "2 1" |
85 | 85 | //! format!("{a} {c} {b}", a="a", b='b', c=3); // => "a 3 b"
|
86 | 86 | //! ```
|
87 | 87 | //!
|
|
104 | 104 | //! octal.
|
105 | 105 | //!
|
106 | 106 | //! There are various parameters which do require a particular type, however.
|
107 |
| -//! Namely, the `{:.*}` syntax, which sets the number of numbers after the |
108 |
| -//! decimal in floating-point types: |
| 107 | +//! An example is the `{:.*}` syntax, which sets the number of decimal places |
| 108 | +//! in floating-point types: |
109 | 109 | //!
|
110 | 110 | //! ```
|
111 | 111 | //! let formatted_number = format!("{:.*}", 2, 1.234567);
|
|
292 | 292 | //! use std::fmt;
|
293 | 293 | //! use std::io::{self, Write};
|
294 | 294 | //!
|
295 |
| -//! fmt::format(format_args!("this returns {}", "String")); |
296 |
| -//! |
297 | 295 | //! let mut some_writer = io::stdout();
|
298 | 296 | //! write!(&mut some_writer, "{}", format_args!("print with a {}", "macro"));
|
299 | 297 | //!
|
300 | 298 | //! fn my_fmt_fn(args: fmt::Arguments) {
|
301 | 299 | //! write!(&mut io::stdout(), "{}", args);
|
302 | 300 | //! }
|
303 |
| -//! my_fmt_fn(format_args!("or a {} too", "function")); |
| 301 | +//! my_fmt_fn(format_args!(", or a {} too", "function")); |
304 | 302 | //! ```
|
305 | 303 | //!
|
306 | 304 | //! The result of the `format_args!` macro is a value of type `fmt::Arguments`.
|
|
316 | 314 | //! # Syntax
|
317 | 315 | //!
|
318 | 316 | //! The syntax for the formatting language used is drawn from other languages,
|
319 |
| -//! so it should not be too alien. Arguments are formatted with python-like |
| 317 | +//! so it should not be too alien. Arguments are formatted with Python-like |
320 | 318 | //! syntax, meaning that arguments are surrounded by `{}` instead of the C-like
|
321 | 319 | //! `%`. The actual grammar for the formatting syntax is:
|
322 | 320 | //!
|
@@ -527,15 +525,15 @@ use string;
|
527 | 525 | /// use std::fmt;
|
528 | 526 | ///
|
529 | 527 | /// let s = fmt::format(format_args!("Hello, {}!", "world"));
|
530 |
| -/// assert_eq!(s, "Hello, world!".to_string()); |
| 528 | +/// assert_eq!(s, "Hello, world!"); |
531 | 529 | /// ```
|
532 | 530 | ///
|
533 | 531 | /// Please note that using [`format!`][format!] might be preferrable.
|
534 | 532 | /// Example:
|
535 | 533 | ///
|
536 | 534 | /// ```
|
537 | 535 | /// let s = format!("Hello, {}!", "world");
|
538 |
| -/// assert_eq!(s, "Hello, world!".to_string()); |
| 536 | +/// assert_eq!(s, "Hello, world!"); |
539 | 537 | /// ```
|
540 | 538 | ///
|
541 | 539 | /// [format!]: ../macro.format!.html
|
|
0 commit comments