The empty tuple is called the unit
-
unit
-
()
-
An empty pair of parentheses
()creates an empty tuple, also called a unit. -
Functions that don’t return anything return the same
unitvalue.
#![allow(clippy::let_unit_value)]
#![allow(clippy::unit_cmp)]
fn main() {
let x = ();
println!("{:?}", x);
let y = ();
println!("{:?}", y);
let same = x == y;
println!("{:?}", same);
let res = empty();
println!("{:?}", res);
assert_eq!(res, ());
let res = no_return();
println!("{:?}", res);
assert_eq!(res, ());
}
fn empty() {}
fn no_return() {
println!("Hello World!");
}
()
()
true
()
Hello World!
()