Ruta graveolens  ·  notes from a language experiment  ·  cultivated since 2025

Unit Type

The unit type, written (), has exactly one value, also written ().

A function without an explicit return type annotation has return type (); its body block evaluates to (), which is the value it returns (see 6.1:4).

Expressions that produce side effects but no meaningful value have type ().

The unit type is a zero-sized type. See Zero-Sized Types for the general definition.

fn do_nothing() {
    // body has no final expression, so it evaluates to ()
}

fn explicit_unit() -> () {
    // returns (), stated explicitly in the signature
}

fn main() -> i32 {
    do_nothing();
    explicit_unit();
    0
}