Skip to content

Commit 0cc8fe5

Browse files
committedDec 12, 2019
Change fmt docs for more delegations
1 parent f284f8b commit 0cc8fe5

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed
 

‎src/libcore/fmt/mod.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,10 @@ impl Display for Arguments<'_> {
455455
///
456456
/// impl fmt::Debug for Point {
457457
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
458-
/// write!(f, "Point {{ x: {}, y: {} }}", self.x, self.y)
458+
/// f.debug_struct("Point")
459+
/// .field("x", &self.x)
460+
/// .field("y", &self.y)
461+
/// .finish()
459462
/// }
460463
/// }
461464
///
@@ -528,7 +531,10 @@ pub trait Debug {
528531
///
529532
/// impl fmt::Debug for Position {
530533
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
531-
/// write!(f, "({:?}, {:?})", self.longitude, self.latitude)
534+
/// f.debug_tuple("")
535+
/// .field(&self.longitude)
536+
/// .field(&self.latitude)
537+
/// .finish()
532538
/// }
533539
/// }
534540
///
@@ -912,8 +918,8 @@ pub trait Pointer {
912918
///
913919
/// impl fmt::LowerExp for Length {
914920
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
915-
/// let val = self.0;
916-
/// write!(f, "{}e1", val / 10)
921+
/// let val = f64::from(self.0);
922+
/// fmt::LowerExp::fmt(&val, f) // delegate to f64's implementation
917923
/// }
918924
/// }
919925
///
@@ -955,8 +961,8 @@ pub trait LowerExp {
955961
///
956962
/// impl fmt::UpperExp for Length {
957963
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
958-
/// let val = self.0;
959-
/// write!(f, "{}E1", val / 10)
964+
/// let val = f64::from(self.0);
965+
/// fmt::UpperExp::fmt(&val, f) // delegate to f64's implementation
960966
/// }
961967
/// }
962968
///

0 commit comments

Comments
 (0)