Struct std::tuple::Tuple

Overview

The tuple type.

Methods

fn len(self) -> u64

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: any) -> 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) -> Iter

Construct an iterator over the tuple.

Examples

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

Trait Implementations

impl PartialEq for Tuple
fn eq(value: any, value1: any) -> bool

Compare two values for equality.

Examples

assert_eq!(1.eq(2), false);
assert_eq!(2.eq(2), true);
assert_eq!(2.eq(1), false);
fn ne(value: any, value1: any) -> bool

Compare two values for inequality.

Examples

assert_eq!(1.ne(2), true);
assert_eq!(2.ne(2), false);
assert_eq!(2.ne(1), true);
impl Eq for Tuple
impl PartialOrd for Tuple
fn partial_cmp(value: any, value1: any) -> Option

Compare two values.

Examples

use std::cmp::Ordering;

assert_eq!(1.partial_cmp(2), Some(Ordering::Less));
assert_eq!(2.partial_cmp(2), Some(Ordering::Equal));
assert_eq!(2.partial_cmp(1), Some(Ordering::Greater));
fn lt(value: any, value1: any) -> bool

Tests less than (for self and other) and is used by the < operator.

Examples

assert_eq!(1.0 < 1.0, false);
assert_eq!(1.0 < 2.0, true);
assert_eq!(2.0 < 1.0, false);
fn le(value: any, value1: any) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator.

Examples

assert_eq!(1.0 <= 1.0, true);
assert_eq!(1.0 <= 2.0, true);
assert_eq!(2.0 <= 1.0, false);
fn gt(value: any, value1: any) -> bool

Tests greater than (for self and other) and is used by the > operator.

Examples

assert_eq!(1.0 > 1.0, false);
assert_eq!(1.0 > 2.0, false);
assert_eq!(2.0 > 1.0, true);
fn ge(value: any, value1: any) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator.

Examples

assert_eq!(1.0 >= 1.0, true);
assert_eq!(1.0 >= 2.0, false);
assert_eq!(2.0 >= 1.0, true);
impl Ord for Tuple
fn cmp(value: any, value1: any) -> Ordering

Compare two values.

Examples

use std::cmp::Ordering;

assert_eq!(1.cmp(2), Ordering::Less);
assert_eq!(2.cmp(2), Ordering::Equal);
assert_eq!(2.cmp(1), Ordering::Greater);
fn min(value: any, value1: any) -> Ordering

Return the minimum of two values.

Examples

assert_eq!(1.min(2), 1);
assert_eq!(2.min(2), 2);
assert_eq!(2.min(1), 1);
fn max(value: any, value1: any) -> Ordering

Return the maximum of two values.

Examples

assert_eq!(1.max(2), 2);
assert_eq!(2.max(2), 2);
assert_eq!(2.max(1), 2);
impl Clone for Tuple
fn clone(value: any) -> any

Clone the specified value.

Examples

let a = 42;
let b = a;
let c = a.clone();

a += 1;

assert_eq!(a, 43);
assert_eq!(b, 42);
assert_eq!(c, 42);

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 CLONE
let $out = clone(value)

Clone a tuple.

Examples

use std::ops::hash;

let a = (0, 2, 3);
let b = a;
let c = a.clone();

c.0 = 1;

assert_eq!(a, (0, 2, 3));
assert_eq!(c, (1, 2, 3));
protocol HASH
let $out = 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]));
protocol DEBUG_FMT
format!("{:?}", value)

Write a debug representation of a tuple.

Examples

let a = (1, 2, 3);
println!("{a:?}");
protocol LT
if $a < $b { }

The protocol behind the < operator.

protocol LE
if $a <= $b { }

The protocol behind the <= operator.

protocol GT
if $a > $b { }

The protocol behind the > operator.

protocol GE
if $a >= $b { }

The protocol behind the >= operator.

protocol MIN
$a.min($b)

The implementation protocol for the PartialOrd::min method.

protocol MAX
$a.max($b)

The implementation protocol for the PartialOrd::max method.