diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs index a5c86d592c636..35b8496f6c57e 100644 --- a/src/libcore/tuple.rs +++ b/src/libcore/tuple.rs @@ -10,6 +10,7 @@ //! Operations on tuples +use clone::Clone; use kinds::Copy; use vec; @@ -46,6 +47,15 @@ impl CopyableTuple for (T, U) { } +impl Clone for (T, U) { + fn clone(&self) -> (T, U) { + let (a, b) = match *self { + (ref a, ref b) => (a, b) + }; + (a.clone(), b.clone()) + } +} + pub trait ImmutableTuple { fn first_ref(&self) -> &'self T; fn second_ref(&self) -> &'self U; @@ -252,3 +262,10 @@ fn test_tuple() { assert!(('a', 2).swap() == (2, 'a')); } +#[test] +fn test_clone() { + let a = (1, ~"2"); + let b = a.clone(); + assert!(a.first() == b.first()); + assert!(a.second() == b.second()); +}