Skip to content

Commit

Permalink
Implement Clone for tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
James Miller committed Apr 3, 2013
1 parent 0cc9030 commit e2bffb7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/libcore/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

//! Operations on tuples

use clone::Clone;
use kinds::Copy;
use vec;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

9 comments on commit e2bffb7

@bors
Copy link
Contributor

@bors bors commented on e2bffb7 Apr 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from thestinger
at Aatch@e2bffb7

@bors
Copy link
Contributor

@bors bors commented on e2bffb7 Apr 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging Aatch/rust/tuple-clone = e2bffb7 into auto

@bors
Copy link
Contributor

@bors bors commented on e2bffb7 Apr 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aatch/rust/tuple-clone = e2bffb7 merged ok, testing candidate = d4e9a415

@bors
Copy link
Contributor

@bors bors commented on e2bffb7 Apr 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on e2bffb7 Apr 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from thestinger
at Aatch@e2bffb7

@bors
Copy link
Contributor

@bors bors commented on e2bffb7 Apr 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging Aatch/rust/tuple-clone = e2bffb7 into auto

@bors
Copy link
Contributor

@bors bors commented on e2bffb7 Apr 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aatch/rust/tuple-clone = e2bffb7 merged ok, testing candidate = afd5cba

@bors
Copy link
Contributor

@bors bors commented on e2bffb7 Apr 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on e2bffb7 Apr 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = afd5cba

Please sign in to comment.