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.
Inserts all new key-values from the iterator and replaces values with existing keys with new values returned from the iterator.
Converts a tuple struct (Into<IpAddr
>, u16
) into a SocketAddr
.
This conversion creates a SocketAddr::V4
for an IpAddr::V4
and creates a SocketAddr::V6
for an IpAddr::V6
.
u16
is treated as port of the newly created SocketAddr
.
impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S> where
K: Eq + Hash,
S: BuildHasher + Default,
impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S> where
K: Eq + Hash,
S: BuildHasher + Default,
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
A: PartialEq<A>,
B: PartialEq<B>,
C: PartialEq<C>,
D: PartialEq<D>,
E: PartialEq<E>,
F: PartialEq<F>,
G: PartialEq<G>,
H: PartialEq<H>,
I: PartialEq<I>,
J: PartialEq<J>,
K: PartialEq<K>,
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
A: PartialEq<A>,
B: PartialEq<B>,
C: PartialEq<C>,
D: PartialEq<D>,
E: PartialEq<E>,
F: PartialEq<F>,
G: PartialEq<G>,
H: PartialEq<H>,
I: PartialEq<I>,
J: PartialEq<J>,
K: PartialEq<K>,
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
A: PartialEq<A>,
B: PartialEq<B>,
C: PartialEq<C>,
D: PartialEq<D>,
E: PartialEq<E>,
F: PartialEq<F>,
G: PartialEq<G>,
H: PartialEq<H>,
I: PartialEq<I>,
J: PartialEq<J>,
K: PartialEq<K> + ?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
A: PartialEq<A>,
B: PartialEq<B>,
C: PartialEq<C>,
D: PartialEq<D>,
E: PartialEq<E>,
F: PartialEq<F>,
G: PartialEq<G>,
H: PartialEq<H>,
I: PartialEq<I>,
J: PartialEq<J>,
K: PartialEq<K> + ?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
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C>,
D: PartialOrd<D> + PartialEq<D>,
E: PartialOrd<E> + PartialEq<E>,
F: PartialOrd<F> + PartialEq<F>,
G: PartialOrd<G> + PartialEq<G>,
H: PartialOrd<H> + PartialEq<H>,
I: PartialOrd<I> + PartialEq<I>,
J: PartialOrd<J> + PartialEq<J>,
K: PartialOrd<K> + PartialEq<K>,
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
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C>,
D: PartialOrd<D> + PartialEq<D>,
E: PartialOrd<E> + PartialEq<E>,
F: PartialOrd<F> + PartialEq<F>,
G: PartialOrd<G> + PartialEq<G>,
H: PartialOrd<H> + PartialEq<H>,
I: PartialOrd<I> + PartialEq<I>,
J: PartialOrd<J> + PartialEq<J>,
K: PartialOrd<K> + PartialEq<K>,
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
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C>,
D: PartialOrd<D> + PartialEq<D>,
E: PartialOrd<E> + PartialEq<E>,
F: PartialOrd<F> + PartialEq<F>,
G: PartialOrd<G> + PartialEq<G>,
H: PartialOrd<H> + PartialEq<H>,
I: PartialOrd<I> + PartialEq<I>,
J: PartialOrd<J> + PartialEq<J>,
K: PartialOrd<K> + PartialEq<K> + ?Sized,
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
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C>,
D: PartialOrd<D> + PartialEq<D>,
E: PartialOrd<E> + PartialEq<E>,
F: PartialOrd<F> + PartialEq<F>,
G: PartialOrd<G> + PartialEq<G>,
H: PartialOrd<H> + PartialEq<H>,
I: PartialOrd<I> + PartialEq<I>,
J: PartialOrd<J> + PartialEq<J>,
K: PartialOrd<K> + PartialEq<K> + ?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> PartialOrd<(A, B, C, D, E, F, G, H, I, J)> for (A, B, C, D, E, F, G, H, I, J) where
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C>,
D: PartialOrd<D> + PartialEq<D>,
E: PartialOrd<E> + PartialEq<E>,
F: PartialOrd<F> + PartialEq<F>,
G: PartialOrd<G> + PartialEq<G>,
H: PartialOrd<H> + PartialEq<H>,
I: PartialOrd<I> + PartialEq<I>,
J: PartialOrd<J> + PartialEq<J> + ?Sized,
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
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C>,
D: PartialOrd<D> + PartialEq<D>,
E: PartialOrd<E> + PartialEq<E>,
F: PartialOrd<F> + PartialEq<F>,
G: PartialOrd<G> + PartialEq<G>,
H: PartialOrd<H> + PartialEq<H>,
I: PartialOrd<I> + PartialEq<I>,
J: PartialOrd<J> + PartialEq<J> + ?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> PartialOrd<(A, B, C, D, E, F, G, H, I)> for (A, B, C, D, E, F, G, H, I) where
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C>,
D: PartialOrd<D> + PartialEq<D>,
E: PartialOrd<E> + PartialEq<E>,
F: PartialOrd<F> + PartialEq<F>,
G: PartialOrd<G> + PartialEq<G>,
H: PartialOrd<H> + PartialEq<H>,
I: PartialOrd<I> + PartialEq<I> + ?Sized,
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
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C>,
D: PartialOrd<D> + PartialEq<D>,
E: PartialOrd<E> + PartialEq<E>,
F: PartialOrd<F> + PartialEq<F>,
G: PartialOrd<G> + PartialEq<G>,
H: PartialOrd<H> + PartialEq<H>,
I: PartialOrd<I> + PartialEq<I> + ?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> PartialOrd<(A, B, C, D, E, F, G, H)> for (A, B, C, D, E, F, G, H) where
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C>,
D: PartialOrd<D> + PartialEq<D>,
E: PartialOrd<E> + PartialEq<E>,
F: PartialOrd<F> + PartialEq<F>,
G: PartialOrd<G> + PartialEq<G>,
H: PartialOrd<H> + PartialEq<H> + ?Sized,
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
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C>,
D: PartialOrd<D> + PartialEq<D>,
E: PartialOrd<E> + PartialEq<E>,
F: PartialOrd<F> + PartialEq<F>,
G: PartialOrd<G> + PartialEq<G>,
H: PartialOrd<H> + PartialEq<H> + ?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> PartialOrd<(A, B, C, D, E, F, G)> for (A, B, C, D, E, F, G) where
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C>,
D: PartialOrd<D> + PartialEq<D>,
E: PartialOrd<E> + PartialEq<E>,
F: PartialOrd<F> + PartialEq<F>,
G: PartialOrd<G> + PartialEq<G> + ?Sized,
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
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C>,
D: PartialOrd<D> + PartialEq<D>,
E: PartialOrd<E> + PartialEq<E>,
F: PartialOrd<F> + PartialEq<F>,
G: PartialOrd<G> + PartialEq<G> + ?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> PartialOrd<(A, B, C, D, E, F)> for (A, B, C, D, E, F) where
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C>,
D: PartialOrd<D> + PartialEq<D>,
E: PartialOrd<E> + PartialEq<E>,
F: PartialOrd<F> + PartialEq<F> + ?Sized,
impl<A, B, C, D, E, F> PartialOrd<(A, B, C, D, E, F)> for (A, B, C, D, E, F) where
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C>,
D: PartialOrd<D> + PartialEq<D>,
E: PartialOrd<E> + PartialEq<E>,
F: PartialOrd<F> + PartialEq<F> + ?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> PartialOrd<(A, B, C, D, E)> for (A, B, C, D, E) where
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C>,
D: PartialOrd<D> + PartialEq<D>,
E: PartialOrd<E> + PartialEq<E> + ?Sized,
impl<A, B, C, D, E> PartialOrd<(A, B, C, D, E)> for (A, B, C, D, E) where
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C>,
D: PartialOrd<D> + PartialEq<D>,
E: PartialOrd<E> + PartialEq<E> + ?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> PartialOrd<(A, B, C, D)> for (A, B, C, D) where
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C>,
D: PartialOrd<D> + PartialEq<D> + ?Sized,
impl<A, B, C, D> PartialOrd<(A, B, C, D)> for (A, B, C, D) where
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C>,
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
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C> + ?Sized,
impl<A, B, C> PartialOrd<(A, B, C)> for (A, B, C) where
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B>,
C: PartialOrd<C> + PartialEq<C> + ?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> PartialOrd<(A, B)> for (A, B) where
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B> + ?Sized,
impl<A, B> PartialOrd<(A, B)> for (A, B) where
A: PartialOrd<A> + PartialEq<A>,
B: PartialOrd<B> + PartialEq<B> + ?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
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 SocketAddr
s. 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 SocketAddr
s. 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 SocketAddr
s. 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 SocketAddr
s. 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 SocketAddr
s. Read more