diff options
Diffstat (limited to 'src/libstd/tuple.rs')
| -rw-r--r-- | src/libstd/tuple.rs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index 45702546278..841be4df6e2 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -12,6 +12,7 @@ #[allow(missing_doc)]; +use clone::Clone; use kinds::Copy; use vec; use vec::ImmutableVector; @@ -19,7 +20,7 @@ use iterator::IteratorUtil; pub use self::inner::*; -/// Method extensions to pairs where both types satisfy the `Copy` bound +/// Method extensions to pairs where both types satisfy the `Clone` bound pub trait CopyableTuple<T, U> { /// Return the first element of self fn first(&self) -> T; @@ -29,12 +30,12 @@ pub trait CopyableTuple<T, U> { fn swap(&self) -> (U, T); } -impl<T:Copy,U:Copy> CopyableTuple<T, U> for (T, U) { +impl<T:Clone,U:Clone> CopyableTuple<T, U> for (T, U) { /// Return the first element of self #[inline] fn first(&self) -> T { match *self { - (ref t, _) => copy *t, + (ref t, _) => (*t).clone(), } } @@ -42,21 +43,21 @@ impl<T:Copy,U:Copy> CopyableTuple<T, U> for (T, U) { #[inline] fn second(&self) -> U { match *self { - (_, ref u) => copy *u, + (_, ref u) => (*u).clone(), } } /// Return the results of swapping the two elements of self #[inline] fn swap(&self) -> (U, T) { - match copy *self { + match (*self).clone() { (t, u) => (u, t), } } } /// Method extensions for pairs where the types don't necessarily satisfy the -/// `Copy` bound +/// `Clone` bound pub trait ImmutableTuple<T, U> { /// Return a reference to the first element of self fn first_ref<'a>(&'a self) -> &'a T; @@ -84,7 +85,11 @@ pub trait ExtendedTupleOps<A,B> { fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C]; } -impl<'self,A:Copy,B:Copy> ExtendedTupleOps<A,B> for (&'self [A], &'self [B]) { +impl<'self, + A:Copy + Clone, + B:Copy + Clone> + ExtendedTupleOps<A,B> for + (&'self [A], &'self [B]) { #[inline] fn zip(&self) -> ~[(A, B)] { match *self { @@ -104,7 +109,10 @@ impl<'self,A:Copy,B:Copy> ExtendedTupleOps<A,B> for (&'self [A], &'self [B]) { } } -impl<A:Copy,B:Copy> ExtendedTupleOps<A,B> for (~[A], ~[B]) { +impl<A:Copy + Clone, + B:Copy + Clone> + ExtendedTupleOps<A,B> for + (~[A], ~[B]) { #[inline] fn zip(&self) -> ~[(A, B)] { match *self { |
