diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-05-01 14:04:13 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-05-10 23:56:57 +0200 |
| commit | 0908d6688203c08e62dc587cc1a9209d8c3e2a52 (patch) | |
| tree | 7b147562843f3418642ae7a7e6ffd46175e9019c | |
| parent | 6e036082091bc253debeb22606a661af211610ff (diff) | |
| download | rust-0908d6688203c08e62dc587cc1a9209d8c3e2a52.tar.gz rust-0908d6688203c08e62dc587cc1a9209d8c3e2a52.zip | |
Doc improvement on std::fmt module
| -rw-r--r-- | src/libcollections/fmt.rs | 12 | ||||
| -rw-r--r-- | src/libcore/fmt/mod.rs | 26 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/libcollections/fmt.rs b/src/libcollections/fmt.rs index e30e0b213af..1f5d542c547 100644 --- a/src/libcollections/fmt.rs +++ b/src/libcollections/fmt.rs @@ -505,12 +505,24 @@ use string; /// /// # Examples /// +/// Basic usage: +/// /// ``` /// use std::fmt; /// /// let s = fmt::format(format_args!("Hello, {}!", "world")); /// assert_eq!(s, "Hello, world!".to_string()); /// ``` +/// +/// Please note that using [`format!`][format!] might be preferrable. +/// Example: +/// +/// ``` +/// let s = format!("Hello, {}!", "world"); +/// assert_eq!(s, "Hello, world!".to_string()); +/// ``` +/// +/// [format!]: ../macro.format!.html #[stable(feature = "rust1", since = "1.0.0")] pub fn format(args: Arguments) -> string::String { let mut output = string::String::new(); diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 0c824b5a8e6..dde4d03dad8 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -776,6 +776,32 @@ pub trait UpperExp { /// /// * output - the buffer to write output to /// * args - the precompiled arguments generated by `format_args!` +/// +/// # Examples +/// +/// Basic usage: +/// +/// ``` +/// use std::fmt; +/// +/// let mut output = String::new(); +/// fmt::write(&mut output, format_args!("Hello {}!", "world")) +/// .expect("Error occurred while trying to write in String"); +/// assert_eq!(output, "Hello world!"); +/// ``` +/// +/// Please note that using [`write!`][write_macro] might be preferrable. Example: +/// +/// ``` +/// use std::fmt::Write; +/// +/// let mut output = String::new(); +/// write!(&mut output, "Hello {}!", "world") +/// .expect("Error occurred while trying to write in String"); +/// assert_eq!(output, "Hello world!"); +/// ``` +/// +/// [write_macro]: ../../std/macro.write!.html #[stable(feature = "rust1", since = "1.0.0")] pub fn write(output: &mut Write, args: Arguments) -> Result { let mut formatter = Formatter { |
