What Is the Unit Type () in Rust?

The unit type () in Rust represents the absence of a value and is used for functions that do not return data.

The unit type () in Rust is a type with exactly one value, also written as (), representing the absence of a meaningful return value. It is used when a function performs an action but does not need to return data, similar to void in other languages.

fn say_hello() {
    println!("Hello!");
}

fn main() {
    let result: () = say_hello(); // Returns ()
}