diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-08-31 16:25:12 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-08-31 16:25:12 +0200 |
| commit | 7f48e8fe6668c5b2fdc62cc70e6bcffb744f411c (patch) | |
| tree | 6ec437098d9f6df511cfbc0805ac51af288c4eec /src/geom/length.rs | |
| parent | 3481d8cc81a2b3a14118869c7f0ffe204ff3efc8 (diff) | |
Make user-facing "debug" representation use Debug instead of Display
Diffstat (limited to 'src/geom/length.rs')
| -rw-r--r-- | src/geom/length.rs | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/geom/length.rs b/src/geom/length.rs index b9eb7b75..d0f11bd2 100644 --- a/src/geom/length.rs +++ b/src/geom/length.rs @@ -130,13 +130,6 @@ impl Length { impl Debug for Length { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - let unit = LengthUnit::Pt; - write!(f, "{}{}", self.to_unit(unit), unit) - } -} - -impl Display for Length { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { use LengthUnit::*; // Format with the unit that yields the shortest output, preferring @@ -147,7 +140,7 @@ impl Display for Length { .min_by_key(|&unit| self.to_unit(unit).to_string().len()) .unwrap(); - write!(f, "{}{}", self.to_unit(unit), unit) + write!(f, "{}{:?}", self.to_unit(unit), unit) } } @@ -219,7 +212,7 @@ impl<'a> Sum<&'a Length> for Length { } /// Different units of length measurement. -#[derive(Debug, Copy, Clone, Eq, PartialEq)] +#[derive(Copy, Clone, Eq, PartialEq)] pub enum LengthUnit { /// Points. Pt, @@ -243,7 +236,7 @@ impl LengthUnit { } } -impl Display for LengthUnit { +impl Debug for LengthUnit { fn fmt(&self, f: &mut Formatter) -> fmt::Result { f.pad(match self { LengthUnit::Mm => "mm", @@ -265,9 +258,9 @@ mod tests { #[test] fn test_length_formatting() { - assert_eq!(Length::pt(23.0).to_string(), "23pt"); - assert_eq!(Length::pt(-28.3465).to_string(), "-1cm"); - assert_eq!(Length::cm(12.728).to_string(), "12.728cm"); - assert_eq!(Length::cm(4.5).to_string(), "45mm"); + assert_eq!(format!("{:?}", Length::pt(23.0)), "23pt"); + assert_eq!(format!("{:?}", Length::pt(-28.3465)), "-1cm"); + assert_eq!(format!("{:?}", Length::cm(12.728)), "12.728cm"); + assert_eq!(format!("{:?}", Length::cm(4.5)), "45mm"); } } |
