Struct ::std::tuple::Tuple

The tuple type.

Methods

fn len(self) -> i64

Returns the number of elements in the tuple.

Examples

let a = (1, 2, 3);
assert_eq!(a.len(), 3);
fn is_empty(self) -> bool

Returns true if the tuple has a length of 0.

Examples

let a = (1, 2, 3);
assert!(!a.is_empty());

let a = ();
assert!(a.is_empty());
fn get(self, index) -> Option

Returns a reference to an element or subslice depending on the type of index.

  • If given a position, returns a reference to the element at that position or None if out of bounds.
  • If given a range, returns the subslice corresponding to that range, or None if out of bounds.

Examples

let v = (10, 40, 30);
assert_eq!(Some(40), v.get(1));
assert_eq!(Some([10, 40]), v.get(0..2));
assert_eq!(None, v.get(3));
assert_eq!(None, v.get(0..4));
fn iter(self) -> Iterator

Construct an iterator over the tuple.

Examples

let tuple = (1, 2, 3);
assert_eq!(tuple.iter().collect::<Vec>(), [1, 2, 3]);

Protocols

protocol into_iter
for item in value { }

Construct an iterator over the tuple.

Examples

let tuple = (1, 2, 3);
let out = [];

for v in tuple {
   out.push(v);
}

assert_eq!(out, [1, 2, 3]);
protocol partial_eq
if value == b { }

Perform a partial equality check with this tuple.

This can take any argument which can be converted into an iterator using [INTO_ITER].

Examples

let tuple = (1, 2, 3);

assert!(tuple == (1, 2, 3));
assert!(tuple == (1..=3));
assert!(tuple != (2, 3, 4));
protocol eq
if value == b { }

Perform a total equality check with this tuple.

Examples

use std::ops::eq;

let tuple = (1, 2, 3);

assert!(eq(tuple, (1, 2, 3)));
assert!(!eq(tuple, (2, 3, 4)));
protocol partial_cmp
if value < b { }

Perform a partial comparison check with this tuple.

Examples

let tuple = (1, 2, 3);

assert!(tuple > (0, 2, 3));
assert!(tuple < (2, 2, 3));
protocol cmp
if value < b { }

Perform a total comparison check with this tuple.

Examples

use std::cmp::Ordering;
use std::ops::cmp;

let tuple = (1, 2, 3);

assert_eq!(cmp(tuple, (0, 2, 3)), Ordering::Greater);
assert_eq!(cmp(tuple, (2, 2, 3)), Ordering::Less);
protocol hash
let output = hash(value)

Calculate a hash for a tuple.

Examples

use std::ops::hash;

assert_eq!(hash((0, 2, 3)), hash((0, 2, 3)));
// Note: this is not guaranteed to be true forever, but it's true right now.
assert_eq!(hash((0, 2, 3)), hash([0, 2, 3]));