The ()
type, also called “unit”, has exactly one value ()
, and is used when there is no other meaningful value that could be returned. It is most commonly seen implicitly: functions without a ->
implicitly have return type ()
, that is, these are equivalent:
fn foo() {}
// vs,
fn foo() -> () {}
Hence explicitly ignoring values of unit type is redundant.
fn foo() {}
fn main() {
let _ = (); // bad
let _ = foo(); // bad
}
fn foo() {}
fn main() {
(); // fine
foo(); // fine
}