@@ -8,16 +8,16 @@ For example, to define a function to zip a pair of tuples into a tuple of pairs:
8
8
``` rust
9
9
#[typle(Tuple for 0..= 12)]
10
10
pub fn zip <A : Tuple , B : Tuple >(
11
- a : A ,
12
- b : B
13
- ) -> typle_for! (i in .. => (A <{i }>, B <{i }>))
11
+ a : A , // (A0, A1,...)
12
+ b : B , // (B0, B1,...)
13
+ ) -> typle_for! (i in .. => (A <{i }>, B <{i }>)) // ((A0, B0), (A1, B1),...)
14
14
{
15
- typle_for! (i in .. => (a [[i ]], b [[i ]]))
15
+ typle_for! (i in .. => (a [[i ]], b [[i ]])) // ((a.0, b.0), (a.1, b.1),...)
16
16
}
17
17
```
18
18
19
19
The types ` A ` and ` B ` are generic but are constrained to be tuples. The tuples
20
- can have 0 to 12 components of any (sized) type, but both parameters must have the
20
+ can have 0 to 12 components of any (sized) type, but both tuples must have the
21
21
same length.
22
22
23
23
``` rust
@@ -26,8 +26,8 @@ assert_eq!(
26
26
((" LHR" , 51.5 ), (" FCO" , 41.8 ), (" ZRH" , 47.5 ))
27
27
);
28
28
assert_eq! (
29
- zip ((2.0 , " test" ), (9u8 , ())),
30
- ((2.0 , 9u8 ), (" test" , ()))
29
+ zip ((2.0 , " test" ), (Some ( 9u8 ) , ('a' , 'b' ))),
30
+ ((2.0 , Some ( 9u8 )) , (" test" , ('a' , 'b' )))
31
31
);
32
32
assert_eq! (
33
33
zip ((), ()),
@@ -37,7 +37,7 @@ assert_eq!(
37
37
38
38
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
- provides simple access to individual components.
40
+ provides access to individual components and their position .
41
41
42
42
For example the ` Hash ` implementation for tuples simply hashes each component of
43
43
the tuple in order.
0 commit comments