Skip to content

Commit

Permalink
Rollup merge of rust-lang#33129 - GuillaumeGomez:fmt_doc, r=steveklabnik
Browse files Browse the repository at this point in the history
Doc improvement on std::fmt module

Part of rust-lang#29355.

r? @steveklabnik
  • Loading branch information
steveklabnik committed May 10, 2016
2 parents d658809 + 1bd4c9d commit b6b3b7b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/libcollections/fmt.rs
Expand Up @@ -521,12 +521,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();
Expand Down
26 changes: 26 additions & 0 deletions src/libcore/fmt/mod.rs
Expand Up @@ -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]: ../macro.write!.html
#[stable(feature = "rust1", since = "1.0.0")]
pub fn write(output: &mut Write, args: Arguments) -> Result {
let mut formatter = Formatter {
Expand Down

0 comments on commit b6b3b7b

Please sign in to comment.