[Rust] Unit Type in Rust

Everything in Rust has a type. Even functions that don't seem to return anything. In such and similar cases, we're dealing with a Unit Type. Learn about it in this lesson.

#[allow(warnings)]

fn main() {
  say_hello();
}

// by default function return a unit type
fn say_hello() {
  println!("Hello!");
}

// the same as
fn say_hello() -> (){
  println!("Hello!");
}

 

posted @ 2024-02-20 22:15  Zhentiw  阅读(7)  评论(0编辑  收藏  举报