Rust functions return the unit by default
- By default function return nothing, more precisely they return
()
the empty tuple which is called theunit
. - We need the
#[allow(clippy::let_unit_value, clippy::unit_cmp)]
in the example to make Clippy, the Rust linter accept this code.
#[allow(clippy::let_unit_value, clippy::unit_cmp)] fn main() { let res = hello_world(); assert_eq!(res, ()); println!("{:?}", res); } fn hello_world() { println!("Hello, world!"); }
Hello, world!
()