summaryrefslogtreecommitdiff
path: root/src/geom
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-03-02 15:45:01 +0100
committerLaurenz <laurmaedje@gmail.com>2021-03-02 15:45:01 +0100
commit45abcf6b2bc247c8c0cba79eb1b0bc36a5d1df43 (patch)
tree3dc454557219d08176d14af052a1c8c68ea82ec0 /src/geom
parent36adbe4b80e57613244adb87301c81c0a23f67f7 (diff)
Remove dependencies on itoa and ryu ⬇️
Diffstat (limited to 'src/geom')
-rw-r--r--src/geom/angle.rs5
-rw-r--r--src/geom/length.rs11
-rw-r--r--src/geom/relative.rs2
3 files changed, 8 insertions, 10 deletions
diff --git a/src/geom/angle.rs b/src/geom/angle.rs
index 07471a02..2392efa5 100644
--- a/src/geom/angle.rs
+++ b/src/geom/angle.rs
@@ -58,14 +58,13 @@ impl Display for Angle {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
// Format with the unit that yields the shortest output, preferring
// degrees when tied.
- let mut buf = ryu::Buffer::new();
let unit = [AngularUnit::Deg, AngularUnit::Rad]
.iter()
.copied()
- .min_by_key(|&unit| buf.format(self.to_unit(unit)).len())
+ .min_by_key(|&unit| self.to_unit(unit).to_string().len())
.unwrap();
- write!(f, "{}{}", buf.format(self.to_unit(unit)), unit)
+ write!(f, "{}{}", self.to_unit(unit), unit)
}
}
diff --git a/src/geom/length.rs b/src/geom/length.rs
index b0ca24df..bc836810 100644
--- a/src/geom/length.rs
+++ b/src/geom/length.rs
@@ -108,14 +108,13 @@ impl Display for Length {
// Format with the unit that yields the shortest output, preferring
// larger / metric units when tied.
- let mut buf = ryu::Buffer::new();
let unit = [Cm, Mm, In, Pt]
.iter()
.copied()
- .min_by_key(|&unit| buf.format(self.to_unit(unit)).len())
+ .min_by_key(|&unit| self.to_unit(unit).to_string().len())
.unwrap();
- write!(f, "{}{}", buf.format(self.to_unit(unit)), unit)
+ write!(f, "{}{}", self.to_unit(unit), unit)
}
}
@@ -239,9 +238,9 @@ mod tests {
#[test]
fn test_length_formatting() {
- assert_eq!(Length::pt(23.0).to_string(), "23.0pt");
- assert_eq!(Length::pt(-28.3465).to_string(), "-1.0cm");
+ 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(), "4.5cm");
+ assert_eq!(Length::cm(4.5).to_string(), "45mm");
}
}
diff --git a/src/geom/relative.rs b/src/geom/relative.rs
index 0eca911e..9d7b3d3e 100644
--- a/src/geom/relative.rs
+++ b/src/geom/relative.rs
@@ -42,7 +42,7 @@ impl Relative {
impl Display for Relative {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- write!(f, "{}%", ryu::Buffer::new().format(100.0 * self.0))
+ write!(f, "{}%", 100.0 * self.0)
}
}