From 70da35dff58b1bb85e184e3e92f8ca1c8db29805 Mon Sep 17 00:00:00 2001 From: dnsl48 Date: Sat, 10 Dec 2016 08:39:06 +1300 Subject: [PATCH] Into<(T,T)> implementation --- rational/src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/rational/src/lib.rs b/rational/src/lib.rs index 6349266..e63ddfb 100644 --- a/rational/src/lib.rs +++ b/rational/src/lib.rs @@ -594,6 +594,12 @@ impl FromStr for Ratio { } } +impl Into<(T, T)> for Ratio { + fn into(self) -> (T, T) { + (self.numer, self.denom) + } +} + #[cfg(feature = "serde")] impl serde::Serialize for Ratio where T: serde::Serialize + Clone + Integer + PartialOrd @@ -1144,4 +1150,11 @@ mod test { assert!(::hash(&_0) != ::hash(&_1)); assert!(::hash(&_0) != ::hash(&_3_2)); } + + #[test] + fn test_into_pair() { + assert_eq! ((0, 1), _0.into()); + assert_eq! ((-2, 1), _NEG2.into()); + assert_eq! ((1, -2), _1_NEG2.into()); + } }