9
9
// except according to those terms.
10
10
11
11
//! Operations on tuples
12
-
13
- #![ allow( missing_doc) ]
12
+ //!
13
+ //! To access a single element of a tuple one can use the following
14
+ //! methods:
15
+ //!
16
+ //! * `valN` - returns a value of _N_-th element
17
+ //! * `refN` - returns a reference to _N_-th element
18
+ //! * `mutN` - returns a mutable reference to _N_-th element
19
+ //!
20
+ //! Indexing starts from zero, so `val0` returns first value, `val1`
21
+ //! returns second value, and so on. In general, a tuple with _S_
22
+ //! elements provides aforementioned methods suffixed with numbers
23
+ //! from `0` to `S-1`. Traits which contain these methods are
24
+ //! implemented for tuples with up to 12 elements.
25
+ //!
26
+ //! If every type inside a tuple implements one of the following
27
+ //! traits, then a tuple itself also implements it.
28
+ //!
29
+ //! * `Clone`
30
+ //! * `Eq`
31
+ //! * `TotalEq`
32
+ //! * `Ord`
33
+ //! * `TotalOrd`
34
+ //! * `Default`
35
+ //!
36
+ //! # Examples
37
+ //!
38
+ //! Using methods:
39
+ //!
40
+ //! ```
41
+ //! let pair = ("pi", 3.14);
42
+ //! assert_eq!(pair.val0(), "pi");
43
+ //! assert_eq!(pair.val1(), 3.14);
44
+ //! ```
45
+ //!
46
+ //! Using traits implemented for tuples:
47
+ //!
48
+ //! ```
49
+ //! use std::default::Default;
50
+ //!
51
+ //! let a = (1, 2);
52
+ //! let b = (3, 4);
53
+ //! assert!(a != b);
54
+ //!
55
+ //! let c = b.clone();
56
+ //! assert!(b == c);
57
+ //!
58
+ //! let d : (u32, f32) = Default::default();
59
+ //! assert_eq!(d, (0u32, 0.0f32));
60
+ //! ```
14
61
15
62
use clone:: Clone ;
16
63
#[ cfg( not( test) ) ] use cmp:: * ;
@@ -26,6 +73,7 @@ macro_rules! tuple_impls {
26
73
}
27
74
) +) => {
28
75
$(
76
+ #[ allow( missing_doc) ]
29
77
pub trait $Tuple<$( $T) ,+> {
30
78
$( fn $valN( self ) -> $T; ) +
31
79
$( fn $refN<' a>( & ' a self ) -> & ' a $T; ) +
0 commit comments