Skip to content

Commit 60c18d4

Browse files
committed
---
yaml --- r: 33150 b: refs/heads/dist-snap c: eb626e7 h: refs/heads/master v: v3
1 parent 3ec7205 commit 60c18d4

File tree

24 files changed

+2206
-2872
lines changed

24 files changed

+2206
-2872
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
10-
refs/heads/dist-snap: d301dd3686ddd04845c1e9f5b9254aa3498a8a7b
10+
refs/heads/dist-snap: eb626e71199d1d89a0242043f096d89941fa2ec7
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/dist-snap/src/libcore/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub use GenericPath = path::GenericPath;
1111
pub use WindowsPath = path::WindowsPath;
1212
pub use PosixPath = path::PosixPath;
1313

14-
pub use tuple::{TupleOps, ExtendedTupleOps};
14+
pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps};
1515
pub use str::{StrSlice, UniqueStr};
1616
pub use vec::{ConstVector, CopyableVector, ImmutableVector};
1717
pub use vec::{ImmutableEqVector, ImmutableCopyableVector};

branches/dist-snap/src/libcore/tuple.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
77
use cmp::{Eq, Ord};
88

9-
pub trait TupleOps<T,U> {
9+
pub trait CopyableTuple<T, U> {
1010
pure fn first() -> T;
1111
pure fn second() -> U;
1212
pure fn swap() -> (U, T);
1313
}
1414

15-
impl<T: Copy, U: Copy> (T, U): TupleOps<T,U> {
15+
impl<T: Copy, U: Copy> (T, U): CopyableTuple<T, U> {
1616

1717
/// Return the first element of self
1818
pure fn first() -> T {
@@ -34,6 +34,24 @@ impl<T: Copy, U: Copy> (T, U): TupleOps<T,U> {
3434

3535
}
3636

37+
pub trait ImmutableTuple<T, U> {
38+
pure fn first_ref(&self) -> &self/T;
39+
pure fn second_ref(&self) -> &self/U;
40+
}
41+
42+
impl<T, U> (T, U): ImmutableTuple<T, U> {
43+
pure fn first_ref(&self) -> &self/T {
44+
match *self {
45+
(ref t, _) => t,
46+
}
47+
}
48+
pure fn second_ref(&self) -> &self/U {
49+
match *self {
50+
(_, ref u) => u,
51+
}
52+
}
53+
}
54+
3755
pub trait ExtendedTupleOps<A,B> {
3856
fn zip(&self) -> ~[(A, B)];
3957
fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C];
@@ -145,6 +163,13 @@ impl<A: Ord, B: Ord, C: Ord> (A, B, C) : Ord {
145163
pure fn gt(other: &(A, B, C)) -> bool { (*other).lt(&self) }
146164
}
147165

166+
#[test]
167+
fn test_tuple_ref() {
168+
let (~"foo", ~"bar");
169+
assert x.first_ref() == &~"foo";
170+
assert x.second_ref() == &~"bar";
171+
}
172+
148173
#[test]
149174
#[allow(non_implicitly_copyable_typarams)]
150175
fn test_tuple() {

0 commit comments

Comments
 (0)