1
1
# typle
2
2
3
- The ` typle ` crate provides the ability to constrain generic arguments to tuples
4
- and supports manipulation of the tuple components.
3
+ The ` typle ` crate provides the ability to constrain generic arguments to be
4
+ tuples and supports manipulation of the tuple components.
5
5
6
6
For example, to define a function to zip a pair of tuples into a tuple of pairs:
7
7
@@ -20,7 +20,7 @@ The types `A` and `B` are generic but are constrained to be tuples. The tuples
20
20
can have 0 to 12 components of any (sized) type, but both parameters must have the
21
21
same length.
22
22
23
- ```
23
+ ``` rust
24
24
assert_eq! (
25
25
zip ((" LHR" , " FCO" , " ZRH" ), (51.5 , 41.8 , 47.5 )),
26
26
((" LHR" , 51.5 ), (" FCO" , 41.8 ), (" ZRH" , 47.5 ))
@@ -39,17 +39,12 @@ A common use of `typle` is to implement a trait for tuples of multiple lengths.
39
39
Compared to using declarative macros, the ` typle ` code looks more Rust-like and
40
40
provides simple access to individual components.
41
41
42
- For example the ` Hash ` trait for tuples simply hashes each component of the
43
- tuple in order.
42
+ For example the ` Hash ` implementation for tuples simply hashes each component of
43
+ the tuple in order.
44
44
45
45
Using ` typle ` this can be written as:
46
46
47
47
``` rust
48
- impl Hash for () {
49
- #[inline]
50
- fn hash <H : Hasher >(& self , _state : & mut H ) {}
51
- }
52
-
53
48
#[typle(Tuple for 1..= 12)]
54
49
impl <T > Hash for T
55
50
where
@@ -70,13 +65,6 @@ Compare this to the current implementation in the standard library:
70
65
71
66
``` rust
72
67
macro_rules! impl_hash_tuple {
73
- () => (
74
- impl Hash for () {
75
- #[inline]
76
- fn hash <H : Hasher >(& self , _state : & mut H ) {}
77
- }
78
- );
79
-
80
68
( $ ($ name : ident )+ ) => (
81
69
impl <$ ($ name : Hash ),+ > Hash for ($ ($ name ,)+ ) where last_type! ($ ($ name ,)+ ): ? Sized {
82
70
#[allow(non_snake_case)]
@@ -94,7 +82,6 @@ macro_rules! last_type {
94
82
($ a : ident , $ ($ rest_a : ident ,)+ ) => { last_type! ($ ($ rest_a ,)+ ) };
95
83
}
96
84
97
- impl_hash_tuple! {}
98
85
impl_hash_tuple! { T }
99
86
impl_hash_tuple! { T B }
100
87
impl_hash_tuple! { T B C }
0 commit comments