diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 66b30d8dd031..9af3645c7893 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -47,6 +47,7 @@ use ops::Add; use util; use num::Zero; use iterator::Iterator; +use iterator; use str::{StrSlice, OwnedStr}; use to_str::ToStr; use clone::DeepClone; @@ -58,31 +59,21 @@ pub enum Option { Some(T), } -impl Ord for Option { +impl Ord for Option { fn lt(&self, other: &Option) -> bool { - match (self, other) { - (&None, &None) => false, - (&None, &Some(_)) => true, - (&Some(_), &None) => false, - (&Some(ref a), &Some(ref b)) => *a < *b - } + iterator::order::lt(self.iter(), other.iter()) } fn le(&self, other: &Option) -> bool { - match (self, other) { - (&None, &None) => true, - (&None, &Some(_)) => true, - (&Some(_), &None) => false, - (&Some(ref a), &Some(ref b)) => *a <= *b - } + iterator::order::le(self.iter(), other.iter()) } fn ge(&self, other: &Option) -> bool { - !(self < other) + iterator::order::ge(self.iter(), other.iter()) } fn gt(&self, other: &Option) -> bool { - !(self <= other) + iterator::order::gt(self.iter(), other.iter()) } } @@ -553,6 +544,18 @@ mod tests { assert!(it.next().is_none()); } + #[test] + fn test_ord() { + let small = Some(1.0); + let big = Some(5.0); + let nan = Some(0.0/0.0); + assert!(!(nan < big)); + assert!(!(nan > big)); + assert!(small < big); + assert!(None < big); + assert!(big > None); + } + #[test] fn test_mutate() { let mut x = Some(3i);