Into<(T,T)> implementation

This commit is contained in:
dnsl48 2016-12-10 08:39:06 +13:00
parent 7db32a4ecd
commit 70da35dff5
1 changed files with 13 additions and 0 deletions

View File

@ -594,6 +594,12 @@ impl<T: FromStr + Clone + Integer> FromStr for Ratio<T> {
} }
} }
impl<T> Into<(T, T)> for Ratio<T> {
fn into(self) -> (T, T) {
(self.numer, self.denom)
}
}
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
impl<T> serde::Serialize for Ratio<T> impl<T> serde::Serialize for Ratio<T>
where T: serde::Serialize + Clone + Integer + PartialOrd where T: serde::Serialize + Clone + Integer + PartialOrd
@ -1144,4 +1150,11 @@ mod test {
assert!(::hash(&_0) != ::hash(&_1)); assert!(::hash(&_0) != ::hash(&_1));
assert!(::hash(&_0) != ::hash(&_3_2)); 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());
}
} }