Expand description
The () type, also called “unit”.
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() {}RunThe 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();
};RunTrait Implementations
impl Extend<()> for ()
1.28.0 · source
impl Extend<()> for ()
1.28.0 · sourcefn extend<T: IntoIterator<Item = ()>>(&mut self, iter: T)
source
fn extend<T: IntoIterator<Item = ()>>(&mut self, iter: T)
sourceExtends a collection with the contents of an iterator. Read more
fn extend_reserve(&mut self, additional: usize)
source
fn extend_reserve(&mut self, additional: usize)
sourceReserves capacity in a collection for the given number of additional elements. Read more
impl FromIterator<()> for ()
1.23.0 · source
impl FromIterator<()> for ()
1.23.0 · sourceCollapses 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:
use std::io::*;
let data = vec![1, 2, 3, 4, 5];
let res: Result<()> = data.iter()
.map(|x| writeln!(stdout(), "{x}"))
.collect();
assert!(res.is_ok());Runfn from_iter<I: IntoIterator<Item = ()>>(iter: I) -> Self
source
fn from_iter<I: IntoIterator<Item = ()>>(iter: I) -> Self
sourceCreates a value from an iterator. Read more
impl Ord for ()
source
impl Ord for ()
sourceimpl PartialOrd<()> for ()
source
impl PartialOrd<()> for ()
sourcefn partial_cmp(&self, _: &()) -> Option<Ordering>
source
fn partial_cmp(&self, _: &()) -> Option<Ordering>
sourceThis method returns an ordering between self and other values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
source
fn lt(&self, other: &Rhs) -> bool
sourceThis method tests less than (for self and other) and is used by the < operator. Read more
fn le(&self, other: &Rhs) -> bool
source
fn le(&self, other: &Rhs) -> bool
sourceThis method tests less than or equal to (for self and other) and is used by the <=
operator. Read more