Module std::tuple[src]

Operations on tuples

To access a single element of a tuple one can use the following methods:

Indexing starts from zero, so val0 returns first value, val1 returns second value, and so on. In general, a tuple with S elements provides aforementioned methods suffixed with numbers from 0 to S-1. Traits which contain these methods are implemented for tuples with up to 12 elements.

If every type inside a tuple implements one of the following traits, then a tuple itself also implements it.

Examples

Using methods:

fn main() { let pair = ("pi", 3.14f64); assert_eq!(pair.val0(), "pi"); assert_eq!(pair.val1(), 3.14f64); }
let pair = ("pi", 3.14f64);
assert_eq!(pair.val0(), "pi");
assert_eq!(pair.val1(), 3.14f64);

Using traits implemented for tuples:

fn main() { use std::default::Default; let a = (1i, 2i); let b = (3i, 4i); assert!(a != b); let c = b.clone(); assert!(b == c); let d : (u32, f32) = Default::default(); assert_eq!(d, (0u32, 0.0f32)); }
use std::default::Default;

let a = (1i, 2i);
let b = (3i, 4i);
assert!(a != b);

let c = b.clone();
assert!(b == c);

let d : (u32, f32) = Default::default();
assert_eq!(d, (0u32, 0.0f32));

Primitive Types

tuple

Operations on tuples

Traits

Tuple1
Tuple10
Tuple11
Tuple12
Tuple2
Tuple3
Tuple4
Tuple5
Tuple6
Tuple7
Tuple8
Tuple9