1.0.0[−]Primitive Type unit
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:
fn long() -> () {} fn short() {}Run
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(); };Run
Trait Implementations
impl FromIterator<()> for ()
1.23.0[src][+]
fn from_iter<I>(iter: I) where
I: IntoIterator<Item = ()>,
[src][−]
I: IntoIterator<Item = ()>,