]> git.proxmox.com Git - rustc.git/blob - src/libstd/tuple.rs
Imported Upstream version 1.2.0+dfsg1
[rustc.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 the _N_-th element of a tuple one can use `N` itself
14 //! as a field of the tuple.
15 //!
16 //! Indexing starts from zero, so `0` returns first value, `1`
17 //! returns second value, and so on. In general, a tuple with _S_
18 //! elements provides aforementioned fields from `0` to `S-1`.
19 //!
20 //! If every type inside a tuple implements one of the following
21 //! traits, then a tuple itself also implements it.
22 //!
23 //! * `Clone`
24 //! * `PartialEq`
25 //! * `Eq`
26 //! * `PartialOrd`
27 //! * `Ord`
28 //! * `Default`
29 //!
30 //! # Examples
31 //!
32 //! Accessing elements of a tuple at specified indices:
33 //!
34 //! ```
35 //! let x = ("colorless", "green", "ideas", "sleep", "furiously");
36 //! assert_eq!(x.3, "sleep");
37 //!
38 //! let v = (3, 3);
39 //! let u = (1, -5);
40 //! assert_eq!(v.0 * u.0 + v.1 * u.1, -12);
41 //! ```
42 //!
43 //! Using traits implemented for tuples:
44 //!
45 //! ```
46 //! let a = (1, 2);
47 //! let b = (3, 4);
48 //! assert!(a != b);
49 //!
50 //! let c = b.clone();
51 //! assert!(b == c);
52 //!
53 //! let d : (u32, f32) = Default::default();
54 //! assert_eq!(d, (0, 0.0f32));
55 //! ```
56
57 #![doc(primitive = "tuple")]
58 #![stable(feature = "rust1", since = "1.0.0")]