about summary refs log tree commit diff
diff options
context:
space:
mode:
authorElichai Turkel <elichai.turkel@gmail.com>2019-12-12 16:03:23 +0200
committerElichai Turkel <elichai.turkel@gmail.com>2019-12-12 16:03:23 +0200
commit0cc8fe5d4306c560b4a2668b01e2df97a4eb80c4 (patch)
tree3b7451a04b1b7c5a994a08135b73c0c4916bd0c8
parentf284f8b4be3a899bf2ecc03e2a1589f486b62a9f (diff)
downloadrust-0cc8fe5d4306c560b4a2668b01e2df97a4eb80c4.tar.gz
rust-0cc8fe5d4306c560b4a2668b01e2df97a4eb80c4.zip
Change fmt docs for more delegations
-rw-r--r--src/libcore/fmt/mod.rs18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs
index e2f49ee25a7..7450a33a1c2 100644
--- a/src/libcore/fmt/mod.rs
+++ b/src/libcore/fmt/mod.rs
@@ -455,7 +455,10 @@ impl Display for Arguments<'_> {
 ///
 /// impl fmt::Debug for Point {
 ///     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-///         write!(f, "Point {{ x: {}, y: {} }}", self.x, self.y)
+///         f.debug_struct("Point")
+///          .field("x", &self.x)
+///          .field("y", &self.y)
+///          .finish()
 ///     }
 /// }
 ///
@@ -528,7 +531,10 @@ pub trait Debug {
     ///
     /// impl fmt::Debug for Position {
     ///     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-    ///         write!(f, "({:?}, {:?})", self.longitude, self.latitude)
+    ///         f.debug_tuple("")
+    ///          .field(&self.longitude)
+    ///          .field(&self.latitude)
+    ///          .finish()
     ///     }
     /// }
     ///
@@ -912,8 +918,8 @@ pub trait Pointer {
 ///
 /// impl fmt::LowerExp for Length {
 ///     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-///         let val = self.0;
-///         write!(f, "{}e1", val / 10)
+///         let val = f64::from(self.0);
+///         fmt::LowerExp::fmt(&val, f) // delegate to f64's implementation
 ///     }
 /// }
 ///
@@ -955,8 +961,8 @@ pub trait LowerExp {
 ///
 /// impl fmt::UpperExp for Length {
 ///     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-///         let val = self.0;
-///         write!(f, "{}E1", val / 10)
+///         let val = f64::from(self.0);
+///         fmt::UpperExp::fmt(&val, f) // delegate to f64's implementation
 ///     }
 /// }
 ///