1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use impl_typed_index;
/// ## TypedIndex
///
/// [`TypedIndex`] enables tuple element access by inferring the *unique* element,
/// type, or passing an explicit numeric index.
///
/// [`TypedIndex::get`] consumes `Self` returning an element, borrows `&Self`, returning
/// an element reference, and mutably borrows `&mut Self` returning a mutable element
/// reference.
///
/// ```rust
/// # use typed_tuple::TypedIndex;
/// let mut tuple = (0u8, 1u16, 2u32);
/// let el_ref: &u16 = (&tuple).get();
/// let el_mut: &mut u16 = (&mut tuple).get();
/// let el: u16 = tuple.get();
/// ```
///
/// ## Get by type
///
/// An index is inferred by either specifying, or inferring a *unique* element type.
///
/// ```rust
/// # use typed_tuple::TypedIndex;
/// let tuple = (0u8, 1u16, 2u32, 3u64, 4u128);
/// let element: u64 = tuple.get(); // Get the unique `u64` element.
/// assert_eq!(element, 3);
/// ```
///
/// ## Get by index
///
/// Where a unique type cannot be specified, the element `INDEX` must be specified.
///
/// ```rust
/// # use typed_tuple::TypedIndex;
/// let tuple = (0u8, 1u16, 2u32, 3u64, 4u128);
/// let element = TypedIndex::<3, _>::get(tuple); // Split at index 3.
/// assert_eq!(element, 3);
/// ```
impl_typed_index!;