about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAriel Ben-Yehuda <arielb1@mail.tau.ac.il>2017-03-11 21:57:40 +0200
committerGitHub <noreply@github.com>2017-03-11 21:57:40 +0200
commitb933bdc7c2edce85186abe68bba37525b6b480a0 (patch)
treeb444e837db467b9cb8de3930a60aaf0986de6b59
parent45de0f90d6e86cb1f5a1aa8c3e785c077aa259ab (diff)
parenta5a3981f1e7865dc9b1e1e1367d6df404893d5cc (diff)
downloadrust-b933bdc7c2edce85186abe68bba37525b6b480a0.tar.gz
rust-b933bdc7c2edce85186abe68bba37525b6b480a0.zip
Rollup merge of #40299 - GuillaumeGomez:fmt-display-example, r=frewsxcv
Add missing example for Display::fmt

r? @frewsxcv
-rw-r--r--src/libcore/fmt/mod.rs21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs
index dc5a662cdb0..1657342ff6a 100644
--- a/src/libcore/fmt/mod.rs
+++ b/src/libcore/fmt/mod.rs
@@ -529,6 +529,26 @@ pub trait Debug {
 #[stable(feature = "rust1", since = "1.0.0")]
 pub trait Display {
     /// Formats the value using the given formatter.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::fmt;
+    ///
+    /// struct Position {
+    ///     longitude: f32,
+    ///     latitude: f32,
+    /// }
+    ///
+    /// impl fmt::Display for Position {
+    ///     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    ///         write!(f, "({}, {})", self.longitude, self.latitude)
+    ///     }
+    /// }
+    ///
+    /// assert_eq!("(1.987, 2.983)".to_owned(),
+    ///            format!("{}", Position { longitude: 1.987, latitude: 2.983, }));
+    /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     fn fmt(&self, f: &mut Formatter) -> Result;
 }
@@ -930,7 +950,6 @@ pub fn write(output: &mut Write, args: Arguments) -> Result {
 }
 
 impl<'a> Formatter<'a> {
-
     // First up is the collection of functions used to execute a format string
     // at runtime. This consumes all of the compile-time statics generated by
     // the format! syntax extension.