Skip to content

Commit e2bffb7

Browse files
author
James Miller
committed
Implement Clone for tuples
1 parent 0cc9030 commit e2bffb7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/libcore/tuple.rs

+17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
//! Operations on tuples
1212
13+
use clone::Clone;
1314
use kinds::Copy;
1415
use vec;
1516

@@ -46,6 +47,15 @@ impl<T:Copy,U:Copy> CopyableTuple<T, U> for (T, U) {
4647

4748
}
4849

50+
impl<T:Clone,U:Clone> Clone for (T, U) {
51+
fn clone(&self) -> (T, U) {
52+
let (a, b) = match *self {
53+
(ref a, ref b) => (a, b)
54+
};
55+
(a.clone(), b.clone())
56+
}
57+
}
58+
4959
pub trait ImmutableTuple<T, U> {
5060
fn first_ref(&self) -> &'self T;
5161
fn second_ref(&self) -> &'self U;
@@ -252,3 +262,10 @@ fn test_tuple() {
252262
assert!(('a', 2).swap() == (2, 'a'));
253263
}
254264
265+
#[test]
266+
fn test_clone() {
267+
let a = (1, ~"2");
268+
let b = a.clone();
269+
assert!(a.first() == b.first());
270+
assert!(a.second() == b.second());
271+
}

0 commit comments

Comments
 (0)