about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorblake2-ppc <blake2-ppc>2013-08-08 22:07:22 +0200
committerblake2-ppc <blake2-ppc>2013-08-08 22:07:22 +0200
commit86da55e85b1f1dd520111b52d1f76c61ea43b382 (patch)
tree413b0a2328e1ca3b733ed91c4a1690832027ac70 /src/libstd
parent9cac4ccc90c135082911c59fa366a88f234c4ecb (diff)
downloadrust-86da55e85b1f1dd520111b52d1f76c61ea43b382.tar.gz
rust-86da55e85b1f1dd520111b52d1f76c61ea43b382.zip
std: Fix Ord for Option, using iterator::order
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/option.rs33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/libstd/option.rs b/src/libstd/option.rs
index 66b30d8dd03..9af3645c789 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<T> {
     Some(T),
 }
 
-impl<T:Ord> Ord for Option<T> {
+impl<T: Eq + Ord> Ord for Option<T> {
     fn lt(&self, other: &Option<T>) -> 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<T>) -> 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<T>) -> bool {
-        !(self < other)
+        iterator::order::ge(self.iter(), other.iter())
     }
 
     fn gt(&self, other: &Option<T>) -> bool {
-        !(self <= other)
+        iterator::order::gt(self.iter(), other.iter())
     }
 }
 
@@ -554,6 +545,18 @@ mod tests {
     }
 
     #[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);
         assert!(x.mutate(|i| i+1));