about summary refs log tree commit diff
path: root/src/libcore/tuple.rs
diff options
context:
space:
mode:
authorSimon BD <simon@server>2012-10-03 21:47:09 -0500
committerSimon BD <simon@server>2012-10-03 21:47:09 -0500
commitefcd2385ea2389f270ff8ac8bc256636f647b130 (patch)
tree7e142ef709bc907a34ab1cb252eef6dcc0e83b91 /src/libcore/tuple.rs
parent44f8a4401ab37a45ba49db56611d77807bcbce35 (diff)
parent3ccf6f5932d8223fd6c5cbf7c6ac429ca9e8912a (diff)
Merge remote-tracking branch 'original/incoming' into incoming
Conflicts:
	src/libstd/json.rs
	src/libstd/sort.rs
Diffstat (limited to 'src/libcore/tuple.rs')
-rw-r--r--src/libcore/tuple.rs70
1 files changed, 35 insertions, 35 deletions
diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs
index 8ec6ed3f0c2..246ce16c813 100644
--- a/src/libcore/tuple.rs
+++ b/src/libcore/tuple.rs
@@ -6,7 +6,7 @@
 
 use cmp::{Eq, Ord};
 
-trait TupleOps<T,U> {
+pub trait TupleOps<T,U> {
     pure fn first() -> T;
     pure fn second() -> U;
     pure fn swap() -> (U, T);
@@ -34,49 +34,54 @@ impl<T: Copy, U: Copy> (T, U): TupleOps<T,U> {
 
 }
 
-trait ExtendedTupleOps<A,B> {
-    fn zip() -> ~[(A, B)];
-    fn map<C>(f: fn(A, B) -> C) -> ~[C];
+pub trait ExtendedTupleOps<A,B> {
+    fn zip(&self) -> ~[(A, B)];
+    fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C];
 }
 
 impl<A: Copy, B: Copy> (&[A], &[B]): ExtendedTupleOps<A,B> {
-
-    fn zip() -> ~[(A, B)] {
-        let (a, b) = self;
-        vec::zip_slice(a, b)
+    fn zip(&self) -> ~[(A, B)] {
+        match *self {
+            (ref a, ref b) => {
+                vec::zip_slice(*a, *b)
+            }
+        }
     }
 
-    fn map<C>(f: fn(A, B) -> C) -> ~[C] {
-        let (a, b) = self;
-        vec::map2(a, b, f)
+    fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C] {
+        match *self {
+            (ref a, ref b) => {
+                vec::map2(*a, *b, f)
+            }
+        }
     }
 }
 
 impl<A: Copy, B: Copy> (~[A], ~[B]): ExtendedTupleOps<A,B> {
 
-    fn zip() -> ~[(A, B)] {
-        // FIXME #2543: Bad copy
-        let (a, b) = copy self;
-        vec::zip(move a, move b)
+    fn zip(&self) -> ~[(A, B)] {
+        match *self {
+            (ref a, ref b) => {
+                vec::zip_slice(*a, *b)
+            }
+        }
     }
 
-    fn map<C>(f: fn(A, B) -> C) -> ~[C] {
-        // FIXME #2543: Bad copy
-        let (a, b) = copy self;
-        vec::map2(a, b, f)
+    fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C] {
+        match *self {
+            (ref a, ref b) => {
+                vec::map2(*a, *b, f)
+            }
+        }
     }
 }
 
 impl<A: Eq, B: Eq> (A, B) : Eq {
     pure fn eq(other: &(A, B)) -> bool {
-        // XXX: This would be a lot less wordy with ref bindings, but I don't
-        // trust that they work yet.
         match self {
-            (self_a, self_b) => {
-                match (*other) {
-                    (ref other_a, ref other_b) => {
-                        self_a.eq(other_a) && self_b.eq(other_b)
-                    }
+            (ref self_a, ref self_b) => match other {
+                &(ref other_a, ref other_b) => {
+                    (*self_a).eq(other_a) && (*self_b).eq(other_b)
                 }
             }
         }
@@ -106,16 +111,11 @@ impl<A: Ord, B: Ord> (A, B) : Ord {
 
 impl<A: Eq, B: Eq, C: Eq> (A, B, C) : Eq {
     pure fn eq(other: &(A, B, C)) -> bool {
-        // XXX: This would be a lot less wordy with ref bindings, but I don't
-        // trust that they work yet.
         match self {
-            (self_a, self_b, self_c) => {
-                match (*other) {
-                    (ref other_a, ref other_b, ref other_c) => {
-                        self_a.eq(other_a) &&
-                        self_b.eq(other_b) &&
-                        self_c.eq(other_c)
-                    }
+            (ref self_a, ref self_b, ref self_c) => match other {
+                &(ref other_a, ref other_b, ref other_c) => {
+                    (*self_a).eq(other_a) && (*self_b).eq(other_b)
+                        && (*self_c).eq(other_c)
                 }
             }
         }