Skip to content

Commit 2cd7a29

Browse files
committed
Merge ImmutableTuple* traits into their respective Tuple* trait
1 parent 6f39eb1 commit 2cd7a29

File tree

2 files changed

+16
-38
lines changed

2 files changed

+16
-38
lines changed

src/libstd/prelude.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ pub use str::{Str, StrVector, StrSlice, OwnedStr, IntoMaybeOwned};
6868
pub use to_bytes::IterBytes;
6969
pub use to_str::{ToStr, IntoStr};
7070
pub use tuple::{CloneableTuple, ImmutableTuple};
71-
pub use tuple::{ImmutableTuple1, ImmutableTuple2, ImmutableTuple3, ImmutableTuple4};
72-
pub use tuple::{ImmutableTuple5, ImmutableTuple6, ImmutableTuple7, ImmutableTuple8};
73-
pub use tuple::{ImmutableTuple9, ImmutableTuple10, ImmutableTuple11, ImmutableTuple12};
7471
pub use tuple::{Tuple1, Tuple2, Tuple3, Tuple4};
7572
pub use tuple::{Tuple5, Tuple6, Tuple7, Tuple8};
7673
pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12};

src/libstd/tuple.rs

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -80,36 +80,28 @@ impl<T, U> ImmutableTuple<T, U> for (T, U) {
8080
}
8181

8282
// macro for implementing n-ary tuple functions and operations
83-
8483
macro_rules! tuple_impls {
8584
($(
86-
($move_trait:ident, $immutable_trait:ident) {
85+
$Tuple:ident {
8786
$(($get_fn:ident, $get_ref_fn:ident) -> $T:ident {
8887
$move_pattern:pat, $ref_pattern:pat => $ret:expr
8988
})+
9089
}
9190
)+) => {
9291
$(
93-
pub trait $move_trait<$($T),+> {
92+
pub trait $Tuple<$($T),+> {
9493
$(fn $get_fn(self) -> $T;)+
94+
$(fn $get_ref_fn<'a>(&'a self) -> &'a $T;)+
9595
}
9696

97-
impl<$($T),+> $move_trait<$($T),+> for ($($T,)+) {
97+
impl<$($T),+> $Tuple<$($T),+> for ($($T,)+) {
9898
$(
9999
#[inline]
100100
fn $get_fn(self) -> $T {
101101
let $move_pattern = self;
102102
$ret
103103
}
104-
)+
105-
}
106-
107-
pub trait $immutable_trait<$($T),+> {
108-
$(fn $get_ref_fn<'a>(&'a self) -> &'a $T;)+
109-
}
110104

111-
impl<$($T),+> $immutable_trait<$($T),+> for ($($T,)+) {
112-
$(
113105
#[inline]
114106
fn $get_ref_fn<'a>(&'a self) -> &'a $T {
115107
let $ref_pattern = *self;
@@ -230,46 +222,40 @@ macro_rules! write_tuple {
230222
}
231223

232224
tuple_impls! {
233-
(Tuple1, ImmutableTuple1) {
225+
Tuple1 {
234226
(n0, n0_ref) -> A { (a,), (ref a,) => a }
235227
}
236-
237-
(Tuple2, ImmutableTuple2) {
228+
Tuple2 {
238229
(n0, n0_ref) -> A { (a,_), (ref a,_) => a }
239230
(n1, n1_ref) -> B { (_,b), (_,ref b) => b }
240231
}
241-
242-
(Tuple3, ImmutableTuple3) {
232+
Tuple3 {
243233
(n0, n0_ref) -> A { (a,_,_), (ref a,_,_) => a }
244234
(n1, n1_ref) -> B { (_,b,_), (_,ref b,_) => b }
245235
(n2, n2_ref) -> C { (_,_,c), (_,_,ref c) => c }
246236
}
247-
248-
(Tuple4, ImmutableTuple4) {
237+
Tuple4 {
249238
(n0, n0_ref) -> A { (a,_,_,_), (ref a,_,_,_) => a }
250239
(n1, n1_ref) -> B { (_,b,_,_), (_,ref b,_,_) => b }
251240
(n2, n2_ref) -> C { (_,_,c,_), (_,_,ref c,_) => c }
252241
(n3, n3_ref) -> D { (_,_,_,d), (_,_,_,ref d) => d }
253242
}
254-
255-
(Tuple5, ImmutableTuple5) {
243+
Tuple5 {
256244
(n0, n0_ref) -> A { (a,_,_,_,_), (ref a,_,_,_,_) => a }
257245
(n1, n1_ref) -> B { (_,b,_,_,_), (_,ref b,_,_,_) => b }
258246
(n2, n2_ref) -> C { (_,_,c,_,_), (_,_,ref c,_,_) => c }
259247
(n3, n3_ref) -> D { (_,_,_,d,_), (_,_,_,ref d,_) => d }
260248
(n4, n4_ref) -> E { (_,_,_,_,e), (_,_,_,_,ref e) => e }
261249
}
262-
263-
(Tuple6, ImmutableTuple6) {
250+
Tuple6 {
264251
(n0, n0_ref) -> A { (a,_,_,_,_,_), (ref a,_,_,_,_,_) => a }
265252
(n1, n1_ref) -> B { (_,b,_,_,_,_), (_,ref b,_,_,_,_) => b }
266253
(n2, n2_ref) -> C { (_,_,c,_,_,_), (_,_,ref c,_,_,_) => c }
267254
(n3, n3_ref) -> D { (_,_,_,d,_,_), (_,_,_,ref d,_,_) => d }
268255
(n4, n4_ref) -> E { (_,_,_,_,e,_), (_,_,_,_,ref e,_) => e }
269256
(n5, n5_ref) -> F { (_,_,_,_,_,f), (_,_,_,_,_,ref f) => f }
270257
}
271-
272-
(Tuple7, ImmutableTuple7) {
258+
Tuple7 {
273259
(n0, n0_ref) -> A { (a,_,_,_,_,_,_), (ref a,_,_,_,_,_,_) => a }
274260
(n1, n1_ref) -> B { (_,b,_,_,_,_,_), (_,ref b,_,_,_,_,_) => b }
275261
(n2, n2_ref) -> C { (_,_,c,_,_,_,_), (_,_,ref c,_,_,_,_) => c }
@@ -278,8 +264,7 @@ tuple_impls! {
278264
(n5, n5_ref) -> F { (_,_,_,_,_,f,_), (_,_,_,_,_,ref f,_) => f }
279265
(n6, n6_ref) -> G { (_,_,_,_,_,_,g), (_,_,_,_,_,_,ref g) => g }
280266
}
281-
282-
(Tuple8, ImmutableTuple8) {
267+
Tuple8 {
283268
(n0, n0_ref) -> A { (a,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_) => a }
284269
(n1, n1_ref) -> B { (_,b,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_) => b }
285270
(n2, n2_ref) -> C { (_,_,c,_,_,_,_,_), (_,_,ref c,_,_,_,_,_) => c }
@@ -289,8 +274,7 @@ tuple_impls! {
289274
(n6, n6_ref) -> G { (_,_,_,_,_,_,g,_), (_,_,_,_,_,_,ref g,_) => g }
290275
(n7, n7_ref) -> H { (_,_,_,_,_,_,_,h), (_,_,_,_,_,_,_,ref h) => h }
291276
}
292-
293-
(Tuple9, ImmutableTuple9) {
277+
Tuple9 {
294278
(n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_) => a }
295279
(n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_) => b }
296280
(n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_) => c }
@@ -301,8 +285,7 @@ tuple_impls! {
301285
(n7, n7_ref) -> H { (_,_,_,_,_,_,_,h,_), (_,_,_,_,_,_,_,ref h,_) => h }
302286
(n8, n8_ref) -> I { (_,_,_,_,_,_,_,_,i), (_,_,_,_,_,_,_,_,ref i) => i }
303287
}
304-
305-
(Tuple10, ImmutableTuple10) {
288+
Tuple10 {
306289
(n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_,_) => a }
307290
(n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_,_) => b }
308291
(n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_,_) => c }
@@ -314,8 +297,7 @@ tuple_impls! {
314297
(n8, n8_ref) -> I { (_,_,_,_,_,_,_,_,i,_), (_,_,_,_,_,_,_,_,ref i,_) => i }
315298
(n9, n9_ref) -> J { (_,_,_,_,_,_,_,_,_,j), (_,_,_,_,_,_,_,_,_,ref j) => j }
316299
}
317-
318-
(Tuple11, ImmutableTuple11) {
300+
Tuple11 {
319301
(n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_,_,_) => a }
320302
(n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_,_,_) => b }
321303
(n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_,_,_) => c }
@@ -328,8 +310,7 @@ tuple_impls! {
328310
(n9, n9_ref) -> J { (_,_,_,_,_,_,_,_,_,j,_), (_,_,_,_,_,_,_,_,_,ref j,_) => j }
329311
(n10, n10_ref) -> K { (_,_,_,_,_,_,_,_,_,_,k), (_,_,_,_,_,_,_,_,_,_,ref k) => k }
330312
}
331-
332-
(Tuple12, ImmutableTuple12) {
313+
Tuple12 {
333314
(n0, n0_ref) -> A { (a,_,_,_,_,_,_,_,_,_,_,_), (ref a,_,_,_,_,_,_,_,_,_,_,_) => a }
334315
(n1, n1_ref) -> B { (_,b,_,_,_,_,_,_,_,_,_,_), (_,ref b,_,_,_,_,_,_,_,_,_,_) => b }
335316
(n2, n2_ref) -> C { (_,_,c,_,_,_,_,_,_,_,_,_), (_,_,ref c,_,_,_,_,_,_,_,_,_) => c }

0 commit comments

Comments
 (0)