Skip to content

Commit

Permalink
Merge ImmutableTuple* traits into their respective Tuple* trait
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanzab committed Feb 16, 2014
1 parent 6f39eb1 commit 2cd7a29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 38 deletions.
3 changes: 0 additions & 3 deletions src/libstd/prelude.rs
Expand Up @@ -68,9 +68,6 @@ pub use str::{Str, StrVector, StrSlice, OwnedStr, IntoMaybeOwned};
pub use to_bytes::IterBytes;
pub use to_str::{ToStr, IntoStr};
pub use tuple::{CloneableTuple, ImmutableTuple};
pub use tuple::{ImmutableTuple1, ImmutableTuple2, ImmutableTuple3, ImmutableTuple4};
pub use tuple::{ImmutableTuple5, ImmutableTuple6, ImmutableTuple7, ImmutableTuple8};
pub use tuple::{ImmutableTuple9, ImmutableTuple10, ImmutableTuple11, ImmutableTuple12};
pub use tuple::{Tuple1, Tuple2, Tuple3, Tuple4};
pub use tuple::{Tuple5, Tuple6, Tuple7, Tuple8};
pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12};
Expand Down
51 changes: 16 additions & 35 deletions src/libstd/tuple.rs
Expand Up @@ -80,36 +80,28 @@ impl<T, U> ImmutableTuple<T, U> for (T, U) {
}

// macro for implementing n-ary tuple functions and operations

macro_rules! tuple_impls {
($(
($move_trait:ident, $immutable_trait:ident) {
$Tuple:ident {
$(($get_fn:ident, $get_ref_fn:ident) -> $T:ident {
$move_pattern:pat, $ref_pattern:pat => $ret:expr
})+
}
)+) => {
$(
pub trait $move_trait<$($T),+> {
pub trait $Tuple<$($T),+> {
$(fn $get_fn(self) -> $T;)+
$(fn $get_ref_fn<'a>(&'a self) -> &'a $T;)+
}

impl<$($T),+> $move_trait<$($T),+> for ($($T,)+) {
impl<$($T),+> $Tuple<$($T),+> for ($($T,)+) {
$(
#[inline]
fn $get_fn(self) -> $T {
let $move_pattern = self;
$ret
}
)+
}

pub trait $immutable_trait<$($T),+> {
$(fn $get_ref_fn<'a>(&'a self) -> &'a $T;)+
}

impl<$($T),+> $immutable_trait<$($T),+> for ($($T,)+) {
$(
#[inline]
fn $get_ref_fn<'a>(&'a self) -> &'a $T {
let $ref_pattern = *self;
Expand Down Expand Up @@ -230,46 +222,40 @@ macro_rules! write_tuple {
}

tuple_impls! {
(Tuple1, ImmutableTuple1) {
Tuple1 {
(n0, n0_ref) -> A { (a,), (ref a,) => a }
}

(Tuple2, ImmutableTuple2) {
Tuple2 {
(n0, n0_ref) -> A { (a,_), (ref a,_) => a }
(n1, n1_ref) -> B { (_,b), (_,ref b) => b }
}

(Tuple3, ImmutableTuple3) {
Tuple3 {
(n0, n0_ref) -> A { (a,_,_), (ref a,_,_) => a }
(n1, n1_ref) -> B { (_,b,_), (_,ref b,_) => b }
(n2, n2_ref) -> C { (_,_,c), (_,_,ref c) => c }
}

(Tuple4, ImmutableTuple4) {
Tuple4 {
(n0, n0_ref) -> A { (a,_,_,_), (ref a,_,_,_) => a }
(n1, n1_ref) -> B { (_,b,_,_), (_,ref b,_,_) => b }
(n2, n2_ref) -> C { (_,_,c,_), (_,_,ref c,_) => c }
(n3, n3_ref) -> D { (_,_,_,d), (_,_,_,ref d) => d }
}

(Tuple5, ImmutableTuple5) {
Tuple5 {
(n0, n0_ref) -> A { (a,_,_,_,_), (ref a,_,_,_,_) => a }
(n1, n1_ref) -> B { (_,b,_,_,_), (_,ref b,_,_,_) => b }
(n2, n2_ref) -> C { (_,_,c,_,_), (_,_,ref c,_,_) => c }
(n3, n3_ref) -> D { (_,_,_,d,_), (_,_,_,ref d,_) => d }
(n4, n4_ref) -> E { (_,_,_,_,e), (_,_,_,_,ref e) => e }
}

(Tuple6, ImmutableTuple6) {
Tuple6 {
(n0, n0_ref) -> A { (a,_,_,_,_,_), (ref a,_,_,_,_,_) => a }
(n1, n1_ref) -> B { (_,b,_,_,_,_), (_,ref b,_,_,_,_) => b }
(n2, n2_ref) -> C { (_,_,c,_,_,_), (_,_,ref c,_,_,_) => c }
(n3, n3_ref) -> D { (_,_,_,d,_,_), (_,_,_,ref d,_,_) => d }
(n4, n4_ref) -> E { (_,_,_,_,e,_), (_,_,_,_,ref e,_) => e }
(n5, n5_ref) -> F { (_,_,_,_,_,f), (_,_,_,_,_,ref f) => f }
}

(Tuple7, ImmutableTuple7) {
Tuple7 {
(n0, n0_ref) -> A { (a,_,_,_,_,_,_), (ref a,_,_,_,_,_,_) => a }
(n1, n1_ref) -> B { (_,b,_,_,_,_,_), (_,ref b,_,_,_,_,_) => b }
(n2, n2_ref) -> C { (_,_,c,_,_,_,_), (_,_,ref c,_,_,_,_) => c }
Expand All @@ -278,8 +264,7 @@ tuple_impls! {
(n5, n5_ref) -> F { (_,_,_,_,_,f,_), (_,_,_,_,_,ref f,_) => f }
(n6, n6_ref) -> G { (_,_,_,_,_,_,g), (_,_,_,_,_,_,ref g) => g }
}

(Tuple8, ImmutableTuple8) {
Tuple8 {
(n0, n0_ref) -> A { (a,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_) => a }
(n1, n1_ref) -> B { (_,b,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_) => b }
(n2, n2_ref) -> C { (_,_,c,_,_,_,_,_), (_,_,ref c,_,_,_,_,_) => c }
Expand All @@ -289,8 +274,7 @@ tuple_impls! {
(n6, n6_ref) -> G { (_,_,_,_,_,_,g,_), (_,_,_,_,_,_,ref g,_) => g }
(n7, n7_ref) -> H { (_,_,_,_,_,_,_,h), (_,_,_,_,_,_,_,ref h) => h }
}

(Tuple9, ImmutableTuple9) {
Tuple9 {
(n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_) => a }
(n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_) => b }
(n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_) => c }
Expand All @@ -301,8 +285,7 @@ tuple_impls! {
(n7, n7_ref) -> H { (_,_,_,_,_,_,_,h,_), (_,_,_,_,_,_,_,ref h,_) => h }
(n8, n8_ref) -> I { (_,_,_,_,_,_,_,_,i), (_,_,_,_,_,_,_,_,ref i) => i }
}

(Tuple10, ImmutableTuple10) {
Tuple10 {
(n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_,_) => a }
(n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_,_) => b }
(n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_,_) => c }
Expand All @@ -314,8 +297,7 @@ tuple_impls! {
(n8, n8_ref) -> I { (_,_,_,_,_,_,_,_,i,_), (_,_,_,_,_,_,_,_,ref i,_) => i }
(n9, n9_ref) -> J { (_,_,_,_,_,_,_,_,_,j), (_,_,_,_,_,_,_,_,_,ref j) => j }
}

(Tuple11, ImmutableTuple11) {
Tuple11 {
(n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_,_,_) => a }
(n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_,_,_) => b }
(n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_,_,_) => c }
Expand All @@ -328,8 +310,7 @@ tuple_impls! {
(n9, n9_ref) -> J { (_,_,_,_,_,_,_,_,_,j,_), (_,_,_,_,_,_,_,_,_,ref j,_) => j }
(n10, n10_ref) -> K { (_,_,_,_,_,_,_,_,_,_,k), (_,_,_,_,_,_,_,_,_,_,ref k) => k }
}

(Tuple12, ImmutableTuple12) {
Tuple12 {
(n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_,_,_,_) => a }
(n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_,_,_,_) => b }
(n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_,_,_,_) => c }
Expand Down

0 comments on commit 2cd7a29

Please sign in to comment.