Skip to content

Commit 0da788a

Browse files
committed
Rollup merge of rust-lang#33129 - GuillaumeGomez:fmt_doc, r=steveklabnik
Doc improvement on std::fmt module Part of rust-lang#29355. r? @steveklabnik
2 parents e1a575c + 0690720 commit 0da788a

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

src/libcollections/fmt.rs

+12
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,24 @@ use string;
516516
///
517517
/// # Examples
518518
///
519+
/// Basic usage:
520+
///
519521
/// ```
520522
/// use std::fmt;
521523
///
522524
/// let s = fmt::format(format_args!("Hello, {}!", "world"));
523525
/// assert_eq!(s, "Hello, world!".to_string());
524526
/// ```
527+
///
528+
/// Please note that using `[format!]` might be preferrable.
529+
/// Example:
530+
///
531+
/// ```
532+
/// let s = format!("Hello, {}!", "world");
533+
/// assert_eq!(s, "Hello, world!".to_string());
534+
/// ```
535+
///
536+
/// [format!]: ../std/macro.format!.html
525537
#[stable(feature = "rust1", since = "1.0.0")]
526538
pub fn format(args: Arguments) -> string::String {
527539
let mut output = string::String::new();

src/libcore/fmt/mod.rs

+26
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,32 @@ pub trait UpperExp {
776776
///
777777
/// * output - the buffer to write output to
778778
/// * args - the precompiled arguments generated by `format_args!`
779+
///
780+
/// # Examples
781+
///
782+
/// Basic usage:
783+
///
784+
/// ```
785+
/// use std::fmt;
786+
///
787+
/// let mut output = String::new();
788+
/// fmt::write(&mut output, format_args!("Hello {}!", "world"))
789+
/// .expect("Error occurred while trying to write in String");
790+
/// assert_eq!(output, "Hello world!");
791+
/// ```
792+
///
793+
/// Please note that using [write!][write_macro] might be preferrable. Example:
794+
///
795+
/// ```
796+
/// use std::fmt::Write;
797+
///
798+
/// let mut output = String::new();
799+
/// write!(&mut output, "Hello {}!", "world")
800+
/// .expect("Error occurred while trying to write in String");
801+
/// assert_eq!(output, "Hello world!");
802+
/// ```
803+
///
804+
/// [write_macro]: ../std/macro.write!.html
779805
#[stable(feature = "rust1", since = "1.0.0")]
780806
pub fn write(output: &mut Write, args: Arguments) -> Result {
781807
let mut formatter = Formatter {

src/liblibc

Submodule liblibc updated 45 files

0 commit comments

Comments
 (0)