The ()
type, sometimes called "unit" or "nil".
The ()
type has exactly one value ()
, and is used when there is no other meaningful value that could be returned. ()
is most commonly seen implicitly: functions without a -> ...
implicitly have return type ()
, that is, these are equivalent:
The semicolon ;
can be used to discard the result of an expression at the end of a block, making the expression (and thus the block) evaluate to ()
. For example,
fn returns_i64() -> i64 { 1i64 } fn returns_unit() { 1i64; } let is_i64 = { returns_i64() }; let is_unit = { returns_i64(); };
impl Extend<()> for ()
[src]1.28.0
fn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = ()>,
[src]
impl Default for ()
[src]
impl Hash for ()
[src]
fn hash<H>(&self, _state: &mut H) where
H: Hasher,
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
[src]1.3.0
Feeds a slice of this type into the given [Hasher
]. Read more
impl Eq for ()
[src]
impl PartialOrd<()> for ()
[src]
fn partial_cmp(&self, &()) -> Option<Ordering>
[src]
fn lt(&self, other: &Rhs) -> bool
[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Ord for ()
[src]
fn cmp(&self, _other: &()) -> Ordering
[src]
fn max(self, other: Self) -> Self
[src]1.21.0
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
[src]1.21.0
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self
[src]
Restrict a value to a certain interval. Read more
impl Debug for ()
[src]
impl PartialEq<()> for ()
[src]
impl FromIterator<()> for ()
[src]1.23.0
Collapses all unit items from an iterator into one.
This is more useful when combined with higher-level abstractions, like collecting to a Result<(), E>
where you only care about errors:
fn from_iter<I>(iter: I) where
I: IntoIterator<Item = ()>,
[src]
impl Termination for ()
[src]
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/primitive.unit.html