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 main() { fn long() -> () {} fn short() {} }
fn long() -> () {}

fn short() {}

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 main() { fn returns_i64() -> i64 { 1i64 } fn returns_unit() { 1i64; } let is_i64 = { returns_i64() }; let is_unit = { returns_i64(); }; }
fn returns_i64() -> i64 {
    1i64
}
fn returns_unit() {
    1i64;
}

let is_i64 = {
    returns_i64()
};
let is_unit = {
    returns_i64();
};

Trait Implementations

impl Rand for ()

fn rand<R: Rng>(&mut R)

impl PartialEq for ()

fn eq(&self, _other: &()) -> bool

fn ne(&self, _other: &()) -> bool

fn ne(&self, &()) -> bool

impl Eq for ()

fn assert_receiver_is_total_eq(&self)

impl PartialOrd for ()

fn partial_cmp(&self, &()) -> Option<Ordering>

fn lt(&self, &()) -> bool

fn le(&self, &()) -> bool

fn gt(&self, &()) -> bool

fn ge(&self, &()) -> bool

impl Ord for ()

fn cmp(&self, _other: &()) -> Ordering

impl Clone for ()

fn clone(&self)

Return a deep copy of the value.

fn clone_from(&mut self, &())

impl Default for ()

fn default()

impl Show for ()

fn fmt(&self, f: &mut Formatter) -> Result<(), FormatError>

impl<S: Writer> Hash<S> for ()

fn hash(&self, state: &mut S)