]> git.lizzy.rs Git - rust.git/blob - src/libstd/tuple.rs
doc: remove incomplete sentence
[rust.git] / src / libstd / tuple.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Operations on tuples
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 //! * `PartialEq`
31 //! * `Eq`
32 //! * `PartialOrd`
33 //! * `Ord`
34 //! * `Default`
35 //!
36 //! # Examples
37 //!
38 //! Using fields:
39 //!
40 //! ```
41 //! #[allow(deprecated)]
42 //! # fn main() {
43 //! let pair = ("pi", 3.14f64);
44 //! assert_eq!(pair.0, "pi");
45 //! assert_eq!(pair.1, 3.14f64);
46 //! # }
47 //! ```
48 //!
49 //! Using traits implemented for tuples:
50 //!
51 //! ```
52 //! use std::default::Default;
53 //!
54 //! let a = (1i, 2i);
55 //! let b = (3i, 4i);
56 //! assert!(a != b);
57 //!
58 //! let c = b.clone();
59 //! assert!(b == c);
60 //!
61 //! let d : (u32, f32) = Default::default();
62 //! assert_eq!(d, (0u32, 0.0f32));
63 //! ```
64
65 #![doc(primitive = "tuple")]
66 #![stable]