about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2017-11-10 17:07:07 +0800
committerGitHub <noreply@github.com>2017-11-10 17:07:07 +0800
commit91cdb0f9bd819584a5cbd0edaeb8e994b6c1f0af (patch)
treec6f9088e5561fba03f6b1a8ad7bfd8bac89f9725
parent65a0fb84ed109d38d6729f838417fdfb9e38c524 (diff)
parent3d480b4138acb67d11767a046e92ff93ca9db72c (diff)
downloadrust-91cdb0f9bd819584a5cbd0edaeb8e994b6c1f0af.tar.gz
rust-91cdb0f9bd819584a5cbd0edaeb8e994b6c1f0af.zip
Rollup merge of #45869 - GuillaumeGomez:debug-doc, r=frewsxcv
Add missing example for Debug trait

r? @rust-lang/docs
-rw-r--r--src/libcore/fmt/mod.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs
index 1e45af5b105..e2d61890c30 100644
--- a/src/libcore/fmt/mod.rs
+++ b/src/libcore/fmt/mod.rs
@@ -525,6 +525,26 @@ impl<'a> Display for Arguments<'a> {
 #[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;
 }