From eb40fbce2a4507362d1a8e108ef2f54f3e097e68 Mon Sep 17 00:00:00 2001 From: ozkriff Date: Tue, 25 Feb 2014 12:56:22 +0400 Subject: [PATCH] Updated to latest Rust: ToStr -> fmt::Show --- src/cgmath/aabb.rs | 12 ++++++------ src/cgmath/angle.rs | 15 +++++++++++++-- src/cgmath/plane.rs | 6 +++--- src/cgmath/point.rs | 12 ++++++------ src/cgmath/quaternion.rs | 10 +++++++--- src/cgmath/transform.rs | 10 +++++----- src/cgmath/vector.rs | 18 +++++++++--------- 7 files changed, 49 insertions(+), 34 deletions(-) diff --git a/src/cgmath/aabb.rs b/src/cgmath/aabb.rs index 0bd26b6..5aa6fdf 100644 --- a/src/cgmath/aabb.rs +++ b/src/cgmath/aabb.rs @@ -93,9 +93,9 @@ impl Aabb, Point2, [S, ..2]> for Aabb2 { #[inline] fn max<'a>(&'a self) -> &'a Point2 { &self.max } } -impl ToStr for Aabb2 { - fn to_str(&self) -> ~str { - format!("[{} - {}]", self.min.to_str(), self.max.to_str()) +impl fmt::Show for Aabb2 { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f.buf, "[{} - {}]", self.min, self.max) } } @@ -122,8 +122,8 @@ impl Aabb, Point3, [S, ..3]> for Aabb3 { #[inline] fn max<'a>(&'a self) -> &'a Point3 { &self.max } } -impl ToStr for Aabb3 { - fn to_str(&self) -> ~str { - format!("[{} - {}]", self.min.to_str(), self.max.to_str()) +impl fmt::Show for Aabb3 { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f.buf, "[{} - {}]", self.min, self.max) } } diff --git a/src/cgmath/angle.rs b/src/cgmath/angle.rs index 98feeec..afbd140 100644 --- a/src/cgmath/angle.rs +++ b/src/cgmath/angle.rs @@ -204,8 +204,19 @@ Angle for Deg { #[inline] pub fn atan(s: S) -> Rad { rad(s.atan()) } #[inline] pub fn atan2(a: S, b: S) -> Rad { rad(a.atan2(&b)) } -impl ToStr for Rad { fn to_str(&self) -> ~str { format!("{} rad", self.s) } } -impl ToStr for Deg { fn to_str(&self) -> ~str { format!("{}°", self.s) } } +impl +fmt::Show for Rad { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f.buf, "{} rad", self.s) + } +} + +impl +fmt::Show for Deg { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f.buf, "{}°", self.s) + } +} impl> ApproxEq for Rad { diff --git a/src/cgmath/plane.rs b/src/cgmath/plane.rs index 5b3f392..a18d2d9 100644 --- a/src/cgmath/plane.rs +++ b/src/cgmath/plane.rs @@ -121,9 +121,9 @@ ApproxEq for Plane { } } -impl ToStr for Plane { - fn to_str(&self) -> ~str { - format!("{:f}x + {:f}y + {:f}z - {:f} = 0", +impl fmt::Show for Plane { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f.buf, "{:f}x + {:f}y + {:f}z - {:f} = 0", self.n.x, self.n.y, self.n.z, diff --git a/src/cgmath/point.rs b/src/cgmath/point.rs index 0a34e97..8a68c74 100644 --- a/src/cgmath/point.rs +++ b/src/cgmath/point.rs @@ -99,14 +99,14 @@ array!(impl Point3 -> [S, ..3] _3) impl Point, [S, ..2]> for Point2 {} impl Point, [S, ..3]> for Point3 {} -impl ToStr for Point2 { - fn to_str(&self) -> ~str { - format!("[{}, {}]", self.x, self.y) +impl fmt::Show for Point2 { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f.buf, "[{}, {}]", self.x, self.y) } } -impl ToStr for Point3 { - fn to_str(&self) -> ~str { - format!("[{}, {}, {}]", self.x, self.y, self.z) +impl fmt::Show for Point3 { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f.buf, "[{}, {}, {}]", self.x, self.y, self.z) } } diff --git a/src/cgmath/quaternion.rs b/src/cgmath/quaternion.rs index 6c4f0b9..da76ab7 100644 --- a/src/cgmath/quaternion.rs +++ b/src/cgmath/quaternion.rs @@ -287,9 +287,13 @@ Neg> for Quat { } } -impl ToStr for Quat { - fn to_str(&self) -> ~str { - format!("{} + {}i + {}j + {}k", self.s, self.v.x, self.v.y, self.v.z) +impl fmt::Show for Quat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f.buf, "{} + {}i + {}j + {}k", + self.s, + self.v.x, + self.v.y, + self.v.z) } } diff --git a/src/cgmath/transform.rs b/src/cgmath/transform.rs index 6a001b6..253d879 100644 --- a/src/cgmath/transform.rs +++ b/src/cgmath/transform.rs @@ -157,11 +157,11 @@ ToMat4 for Decomposed, R> { impl, R: Rotation3> Transform3 for Decomposed,R> {} -impl> -ToStr for Decomposed,R> { - fn to_str(&self) -> ~str { - format!("(scale({}), rot({:s}), disp{:s})", - self.scale, self.rot.to_str(), self.disp.to_str()) +impl> +fmt::Show for Decomposed,R> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f.buf, "(scale({}), rot({}), disp{})", + self.scale, self.rot, self.disp) } } diff --git a/src/cgmath/vector.rs b/src/cgmath/vector.rs index 3582a80..d5d4f76 100644 --- a/src/cgmath/vector.rs +++ b/src/cgmath/vector.rs @@ -302,20 +302,20 @@ EuclideanVector for Vec4 { } } -impl ToStr for Vec2 { - fn to_str(&self) -> ~str { - format!("[{}, {}]", self.x, self.y) +impl fmt::Show for Vec2 { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f.buf, "[{}, {}]", self.x, self.y) } } -impl ToStr for Vec3 { - fn to_str(&self) -> ~str { - format!("[{}, {}, {}]", self.x, self.y, self.z) +impl fmt::Show for Vec3 { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f.buf, "[{}, {}, {}]", self.x, self.y, self.z) } } -impl ToStr for Vec4 { - fn to_str(&self) -> ~str { - format!("[{}, {}, {}, {}]", self.x, self.y, self.z, self.w) +impl fmt::Show for Vec4 { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f.buf, "[{}, {}, {}, {}]", self.x, self.y, self.z, self.w) } }