about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-04-03 01:15:49 -0700
committerbors <bors@rust-lang.org>2013-04-03 01:15:49 -0700
commitafd5cba38c6f1ccbd30ce732d8da5abdf5ed556f (patch)
tree1722928c2b7fda138fd9f663daf402a036e17368
parent0cc903015b395c0d9eada3fe3376f2447cc835b6 (diff)
parente2bffb79717f7622e97870c3194435b06e3e56bc (diff)
downloadrust-afd5cba38c6f1ccbd30ce732d8da5abdf5ed556f.tar.gz
rust-afd5cba38c6f1ccbd30ce732d8da5abdf5ed556f.zip
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.
-rw-r--r--src/libcore/tuple.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs
index a5c86d592c6..35b8496f6c5 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<T:Copy,U:Copy> CopyableTuple<T, U> for (T, U) {
 
 }
 
+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());
+}