From 0cc8fe5d4306c560b4a2668b01e2df97a4eb80c4 Mon Sep 17 00:00:00 2001 From: Elichai Turkel Date: Thu, 12 Dec 2019 16:03:23 +0200 Subject: Change fmt docs for more delegations --- src/libcore/fmt/mod.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/libcore') 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 /// } /// } /// -- cgit 1.4.1-3-g733a5