Primitive Type tuple1.0.0[−]
Expand description
A finite heterogeneous sequence, (T, U, ..).
Let’s cover each of those in turn:
Tuples are finite. In other words, a tuple has a length. Here’s a tuple
of length 3:
("hello", 5, 'c');Run‘Length’ is also sometimes called ‘arity’ here; each tuple of a different length is a different, distinct type.
Tuples are heterogeneous. This means that each element of the tuple can have a different type. In that tuple above, it has the type:
(&'static str, i32, char)RunTuples are a sequence. This means that they can be accessed by position; this is called ‘tuple indexing’, and it looks like this:
let tuple = ("hello", 5, 'c');
assert_eq!(tuple.0, "hello");
assert_eq!(tuple.1, 5);
assert_eq!(tuple.2, 'c');RunThe sequential nature of the tuple applies to its implementations of various
traits. For example, in PartialOrd and Ord, the elements are compared
sequentially until the first non-equal set is found.
For more about tuples, see the book.
Trait implementations
If every type inside a tuple implements one of the following traits, then a tuple itself also implements it.
Due to a temporary restriction in Rust’s type system, these traits are only implemented on tuples of arity 12 or less. In the future, this may change.
Examples
Basic usage:
let tuple = ("hello", 5, 'c');
assert_eq!(tuple.0, "hello");RunTuples are often used as a return type when you want to return more than one value:
fn calculate_point() -> (i32, i32) {
// Don't do a calculation, that's not the point of the example
(4, 5)
}
let point = calculate_point();
assert_eq!(point.0, 4);
assert_eq!(point.1, 5);
// Combining this with patterns can be nicer.
let (x, y) = calculate_point();
assert_eq!(x, 4);
assert_eq!(y, 5);RunTrait Implementations
Allows to extend a tuple of collections that also implement Extend.
See also: Iterator::unzip
Examples
let mut tuple = (vec![0], vec![1]);
tuple.extend([(2, 3), (4, 5), (6, 7)]);
assert_eq!(tuple.0, [0, 2, 4, 6]);
assert_eq!(tuple.1, [1, 3, 5, 7]);
// also allows for arbitrarily nested tuples as elements
let mut nested_tuple = (vec![1], (vec![2], vec![3]));
nested_tuple.extend([(4, (5, 6)), (7, (8, 9))]);
let (a, (b, c)) = nested_tuple;
assert_eq!(a, [1, 4, 7]);
assert_eq!(b, [2, 5, 8]);
assert_eq!(c, [3, 6, 9]);RunExtends a collection with exactly one element.
impl<A, B, C, D, E, F, G, H, I, J, K, L> PartialEq<(A, B, C, D, E, F, G, H, I, J, K, L)> for (A, B, C, D, E, F, G, H, I, J, K, L) where
C: PartialEq<C>,
F: PartialEq<F>,
K: PartialEq<K>,
I: PartialEq<I>,
E: PartialEq<E>,
H: PartialEq<H>,
B: PartialEq<B>,
A: PartialEq<A>,
J: PartialEq<J>,
G: PartialEq<G>,
D: PartialEq<D>,
L: PartialEq<L> + ?Sized,
impl<A, B, C, D, E, F, G, H, I, J, K, L> PartialEq<(A, B, C, D, E, F, G, H, I, J, K, L)> for (A, B, C, D, E, F, G, H, I, J, K, L) where
C: PartialEq<C>,
F: PartialEq<F>,
K: PartialEq<K>,
I: PartialEq<I>,
E: PartialEq<E>,
H: PartialEq<H>,
B: PartialEq<B>,
A: PartialEq<A>,
J: PartialEq<J>,
G: PartialEq<G>,
D: PartialEq<D>,
L: PartialEq<L> + ?Sized,
impl<A, B, C, D, E, F, G, H, I, J, K> PartialEq<(A, B, C, D, E, F, G, H, I, J, K)> for (A, B, C, D, E, F, G, H, I, J, K) where
C: PartialEq<C>,
F: PartialEq<F>,
K: PartialEq<K> + ?Sized,
I: PartialEq<I>,
E: PartialEq<E>,
H: PartialEq<H>,
B: PartialEq<B>,
A: PartialEq<A>,
J: PartialEq<J>,
G: PartialEq<G>,
D: PartialEq<D>,
impl<A, B, C, D, E, F, G, H, I, J, K> PartialEq<(A, B, C, D, E, F, G, H, I, J, K)> for (A, B, C, D, E, F, G, H, I, J, K) where
C: PartialEq<C>,
F: PartialEq<F>,
K: PartialEq<K> + ?Sized,
I: PartialEq<I>,
E: PartialEq<E>,
H: PartialEq<H>,
B: PartialEq<B>,
A: PartialEq<A>,
J: PartialEq<J>,
G: PartialEq<G>,
D: PartialEq<D>,
impl<A, B, C, D, E, F, G, H, I, J, K, L> PartialOrd<(A, B, C, D, E, F, G, H, I, J, K, L)> for (A, B, C, D, E, F, G, H, I, J, K, L) where
C: PartialOrd<C> + PartialEq<C>,
F: PartialOrd<F> + PartialEq<F>,
K: PartialOrd<K> + PartialEq<K>,
I: PartialOrd<I> + PartialEq<I>,
E: PartialOrd<E> + PartialEq<E>,
H: PartialOrd<H> + PartialEq<H>,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
J: PartialOrd<J> + PartialEq<J>,
G: PartialOrd<G> + PartialEq<G>,
D: PartialOrd<D> + PartialEq<D>,
L: PartialOrd<L> + PartialEq<L> + ?Sized,
impl<A, B, C, D, E, F, G, H, I, J, K, L> PartialOrd<(A, B, C, D, E, F, G, H, I, J, K, L)> for (A, B, C, D, E, F, G, H, I, J, K, L) where
C: PartialOrd<C> + PartialEq<C>,
F: PartialOrd<F> + PartialEq<F>,
K: PartialOrd<K> + PartialEq<K>,
I: PartialOrd<I> + PartialEq<I>,
E: PartialOrd<E> + PartialEq<E>,
H: PartialOrd<H> + PartialEq<H>,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
J: PartialOrd<J> + PartialEq<J>,
G: PartialOrd<G> + PartialEq<G>,
D: PartialOrd<D> + PartialEq<D>,
L: PartialOrd<L> + PartialEq<L> + ?Sized,
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >=
operator. Read more
impl<A, B, C, D, E, F, G, H, I, J, K> PartialOrd<(A, B, C, D, E, F, G, H, I, J, K)> for (A, B, C, D, E, F, G, H, I, J, K) where
C: PartialOrd<C> + PartialEq<C>,
F: PartialOrd<F> + PartialEq<F>,
K: PartialOrd<K> + PartialEq<K> + ?Sized,
I: PartialOrd<I> + PartialEq<I>,
E: PartialOrd<E> + PartialEq<E>,
H: PartialOrd<H> + PartialEq<H>,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
J: PartialOrd<J> + PartialEq<J>,
G: PartialOrd<G> + PartialEq<G>,
D: PartialOrd<D> + PartialEq<D>,
impl<A, B, C, D, E, F, G, H, I, J, K> PartialOrd<(A, B, C, D, E, F, G, H, I, J, K)> for (A, B, C, D, E, F, G, H, I, J, K) where
C: PartialOrd<C> + PartialEq<C>,
F: PartialOrd<F> + PartialEq<F>,
K: PartialOrd<K> + PartialEq<K> + ?Sized,
I: PartialOrd<I> + PartialEq<I>,
E: PartialOrd<E> + PartialEq<E>,
H: PartialOrd<H> + PartialEq<H>,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
J: PartialOrd<J> + PartialEq<J>,
G: PartialOrd<G> + PartialEq<G>,
D: PartialOrd<D> + PartialEq<D>,
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >=
operator. Read more
impl<A, B, C, D, E, F, G, H, I, J> PartialOrd<(A, B, C, D, E, F, G, H, I, J)> for (A, B, C, D, E, F, G, H, I, J) where
C: PartialOrd<C> + PartialEq<C>,
F: PartialOrd<F> + PartialEq<F>,
I: PartialOrd<I> + PartialEq<I>,
E: PartialOrd<E> + PartialEq<E>,
H: PartialOrd<H> + PartialEq<H>,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
J: PartialOrd<J> + PartialEq<J> + ?Sized,
G: PartialOrd<G> + PartialEq<G>,
D: PartialOrd<D> + PartialEq<D>,
impl<A, B, C, D, E, F, G, H, I, J> PartialOrd<(A, B, C, D, E, F, G, H, I, J)> for (A, B, C, D, E, F, G, H, I, J) where
C: PartialOrd<C> + PartialEq<C>,
F: PartialOrd<F> + PartialEq<F>,
I: PartialOrd<I> + PartialEq<I>,
E: PartialOrd<E> + PartialEq<E>,
H: PartialOrd<H> + PartialEq<H>,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
J: PartialOrd<J> + PartialEq<J> + ?Sized,
G: PartialOrd<G> + PartialEq<G>,
D: PartialOrd<D> + PartialEq<D>,
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >=
operator. Read more
impl<A, B, C, D, E, F, G, H, I> PartialOrd<(A, B, C, D, E, F, G, H, I)> for (A, B, C, D, E, F, G, H, I) where
C: PartialOrd<C> + PartialEq<C>,
F: PartialOrd<F> + PartialEq<F>,
I: PartialOrd<I> + PartialEq<I> + ?Sized,
E: PartialOrd<E> + PartialEq<E>,
H: PartialOrd<H> + PartialEq<H>,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
G: PartialOrd<G> + PartialEq<G>,
D: PartialOrd<D> + PartialEq<D>,
impl<A, B, C, D, E, F, G, H, I> PartialOrd<(A, B, C, D, E, F, G, H, I)> for (A, B, C, D, E, F, G, H, I) where
C: PartialOrd<C> + PartialEq<C>,
F: PartialOrd<F> + PartialEq<F>,
I: PartialOrd<I> + PartialEq<I> + ?Sized,
E: PartialOrd<E> + PartialEq<E>,
H: PartialOrd<H> + PartialEq<H>,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
G: PartialOrd<G> + PartialEq<G>,
D: PartialOrd<D> + PartialEq<D>,
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >=
operator. Read more
impl<A, B, C, D, E, F, G, H> PartialOrd<(A, B, C, D, E, F, G, H)> for (A, B, C, D, E, F, G, H) where
C: PartialOrd<C> + PartialEq<C>,
F: PartialOrd<F> + PartialEq<F>,
E: PartialOrd<E> + PartialEq<E>,
H: PartialOrd<H> + PartialEq<H> + ?Sized,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
G: PartialOrd<G> + PartialEq<G>,
D: PartialOrd<D> + PartialEq<D>,
impl<A, B, C, D, E, F, G, H> PartialOrd<(A, B, C, D, E, F, G, H)> for (A, B, C, D, E, F, G, H) where
C: PartialOrd<C> + PartialEq<C>,
F: PartialOrd<F> + PartialEq<F>,
E: PartialOrd<E> + PartialEq<E>,
H: PartialOrd<H> + PartialEq<H> + ?Sized,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
G: PartialOrd<G> + PartialEq<G>,
D: PartialOrd<D> + PartialEq<D>,
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >=
operator. Read more
impl<A, B, C, D, E, F, G> PartialOrd<(A, B, C, D, E, F, G)> for (A, B, C, D, E, F, G) where
C: PartialOrd<C> + PartialEq<C>,
F: PartialOrd<F> + PartialEq<F>,
E: PartialOrd<E> + PartialEq<E>,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
G: PartialOrd<G> + PartialEq<G> + ?Sized,
D: PartialOrd<D> + PartialEq<D>,
impl<A, B, C, D, E, F, G> PartialOrd<(A, B, C, D, E, F, G)> for (A, B, C, D, E, F, G) where
C: PartialOrd<C> + PartialEq<C>,
F: PartialOrd<F> + PartialEq<F>,
E: PartialOrd<E> + PartialEq<E>,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
G: PartialOrd<G> + PartialEq<G> + ?Sized,
D: PartialOrd<D> + PartialEq<D>,
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >=
operator. Read more
impl<A, B, C, D, E, F> PartialOrd<(A, B, C, D, E, F)> for (A, B, C, D, E, F) where
C: PartialOrd<C> + PartialEq<C>,
F: PartialOrd<F> + PartialEq<F> + ?Sized,
E: PartialOrd<E> + PartialEq<E>,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
D: PartialOrd<D> + PartialEq<D>,
impl<A, B, C, D, E, F> PartialOrd<(A, B, C, D, E, F)> for (A, B, C, D, E, F) where
C: PartialOrd<C> + PartialEq<C>,
F: PartialOrd<F> + PartialEq<F> + ?Sized,
E: PartialOrd<E> + PartialEq<E>,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
D: PartialOrd<D> + PartialEq<D>,
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >=
operator. Read more
impl<A, B, C, D, E> PartialOrd<(A, B, C, D, E)> for (A, B, C, D, E) where
C: PartialOrd<C> + PartialEq<C>,
E: PartialOrd<E> + PartialEq<E> + ?Sized,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
D: PartialOrd<D> + PartialEq<D>,
impl<A, B, C, D, E> PartialOrd<(A, B, C, D, E)> for (A, B, C, D, E) where
C: PartialOrd<C> + PartialEq<C>,
E: PartialOrd<E> + PartialEq<E> + ?Sized,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
D: PartialOrd<D> + PartialEq<D>,
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >=
operator. Read more
impl<A, B, C, D> PartialOrd<(A, B, C, D)> for (A, B, C, D) where
C: PartialOrd<C> + PartialEq<C>,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
D: PartialOrd<D> + PartialEq<D> + ?Sized,
impl<A, B, C, D> PartialOrd<(A, B, C, D)> for (A, B, C, D) where
C: PartialOrd<C> + PartialEq<C>,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
D: PartialOrd<D> + PartialEq<D> + ?Sized,
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >=
operator. Read more
impl<A, B, C> PartialOrd<(A, B, C)> for (A, B, C) where
C: PartialOrd<C> + PartialEq<C> + ?Sized,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
impl<A, B, C> PartialOrd<(A, B, C)> for (A, B, C) where
C: PartialOrd<C> + PartialEq<C> + ?Sized,
B: PartialOrd<B> + PartialEq<B>,
A: PartialOrd<A> + PartialEq<A>,
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >=
operator. Read more
impl<A, B> PartialOrd<(A, B)> for (A, B) where
B: PartialOrd<B> + PartialEq<B> + ?Sized,
A: PartialOrd<A> + PartialEq<A>,
impl<A, B> PartialOrd<(A, B)> for (A, B) where
B: PartialOrd<B> + PartialEq<B> + ?Sized,
A: PartialOrd<A> + PartialEq<A>,
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >=
operator. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >=
operator. Read more
slice_index_methods)Returns a shared reference to the output at this location, if in bounds. Read more
slice_index_methods)Returns a mutable reference to the output at this location, if in bounds. Read more
slice_index_methods)Returns a shared reference to the output at this location, without
performing any bounds checking.
Calling this method with an out-of-bounds index or a dangling slice pointer
is undefined behavior even if the resulting reference is not used. Read more
slice_index_methods)Returns a mutable reference to the output at this location, without
performing any bounds checking.
Calling this method with an out-of-bounds index or a dangling slice pointer
is undefined behavior even if the resulting reference is not used. Read more
slice_index_methods)Returns a shared reference to the output at this location, panicking if out of bounds. Read more
type Iter = IntoIter<SocketAddr>
type Iter = IntoIter<SocketAddr>
Returned iterator over socket addresses which this type may correspond to. Read more
Converts this object to an iterator of resolved SocketAddrs. Read more
type Iter = IntoIter<SocketAddr>
type Iter = IntoIter<SocketAddr>
Returned iterator over socket addresses which this type may correspond to. Read more
Converts this object to an iterator of resolved SocketAddrs. Read more
type Iter = IntoIter<SocketAddr>
type Iter = IntoIter<SocketAddr>
Returned iterator over socket addresses which this type may correspond to. Read more
Converts this object to an iterator of resolved SocketAddrs. Read more
type Iter = IntoIter<SocketAddr>
type Iter = IntoIter<SocketAddr>
Returned iterator over socket addresses which this type may correspond to. Read more
Converts this object to an iterator of resolved SocketAddrs. Read more
type Iter = IntoIter<SocketAddr>
type Iter = IntoIter<SocketAddr>
Returned iterator over socket addresses which this type may correspond to. Read more
Converts this object to an iterator of resolved SocketAddrs. Read more