auto merge of #5692 : Aatch/rust/tuple-clone, r=thestinger

This implements the clone interface for tuples and adds a test to match. The implementation is only on tuples that have elements that are themselves clone-able. This should allow for `#[deriving(Clone)] on nominal types that contain tuples somewhere.
This commit is contained in:
bors 2013-04-03 01:15:49 -07:00
commit afd5cba38c

View File

@ -10,6 +10,7 @@
//! Operations on tuples
use clone::Clone;
use kinds::Copy;
use vec;
@ -46,6 +47,15 @@ fn swap(&self) -> (U, T) {
}
impl<T:Clone,U:Clone> 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<T, U> {
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());
}