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.
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.
11 //! Operations on tuples
13 //! To access the _N_-th element of a tuple one can use `N` itself
14 //! as a field of the tuple.
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`.
20 //! If every type inside a tuple implements one of the following
21 //! traits, then a tuple itself also implements it.
32 //! Accessing elements of a tuple at specified indices:
35 //! let x = ("colorless", "green", "ideas", "sleep", "furiously");
36 //! assert_eq!(x.3, "sleep");
39 //! let u = (1i, -5i);
40 //! assert_eq!(v.0 * u.0 + v.1 * u.1, -12i);
43 //! Using traits implemented for tuples:
46 //! use std::default::Default;
52 //! let c = b.clone();
55 //! let d : (u32, f32) = Default::default();
56 //! assert_eq!(d, (0u32, 0.0f32));
59 #![doc(primitive = "tuple")]
60 #![stable(feature = "rust1", since = "1.0.0")]