]> git.lizzy.rs Git - rust.git/commitdiff
Add missing example for Debug trait
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Wed, 8 Nov 2017 13:11:27 +0000 (14:11 +0100)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Wed, 8 Nov 2017 13:11:27 +0000 (14:11 +0100)
src/libcore/fmt/mod.rs

index 1e45af5b105c9ca2c50f448bcbee27c394ba1f5a..e2d61890c309681ab87d29e908bb93c753d3a402 100644 (file)
@@ -525,6 +525,26 @@ fn fmt(&self, fmt: &mut Formatter) -> Result {
 #[lang = "debug_trait"]
 pub trait Debug {
     /// Formats the value using the given formatter.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::fmt;
+    ///
+    /// struct Position {
+    ///     longitude: f32,
+    ///     latitude: f32,
+    /// }
+    ///
+    /// impl fmt::Debug 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;
 }