File tree 2 files changed +38
-0
lines changed
2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -521,12 +521,24 @@ use string;
521
521
///
522
522
/// # Examples
523
523
///
524
+ /// Basic usage:
525
+ ///
524
526
/// ```
525
527
/// use std::fmt;
526
528
///
527
529
/// let s = fmt::format(format_args!("Hello, {}!", "world"));
528
530
/// assert_eq!(s, "Hello, world!".to_string());
529
531
/// ```
532
+ ///
533
+ /// Please note that using [`format!`][format!] might be preferrable.
534
+ /// Example:
535
+ ///
536
+ /// ```
537
+ /// let s = format!("Hello, {}!", "world");
538
+ /// assert_eq!(s, "Hello, world!".to_string());
539
+ /// ```
540
+ ///
541
+ /// [format!]: ../macro.format!.html
530
542
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
531
543
pub fn format ( args : Arguments ) -> string:: String {
532
544
let mut output = string:: String :: new ( ) ;
Original file line number Diff line number Diff line change @@ -776,6 +776,32 @@ pub trait UpperExp {
776
776
///
777
777
/// * output - the buffer to write output to
778
778
/// * 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
779
805
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
780
806
pub fn write ( output : & mut Write , args : Arguments ) -> Result {
781
807
let mut formatter = Formatter {
You can’t perform that action at this time.
0 commit comments