Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Return the last expression (no return)

  • If the last thing in the function is an expression (no semi-colon at the end) then this is the returned value.
  • No need for the return statement.
fn main() {
    println!("{}", add(2, 3));
    println!("{}", add(3, 4));
}

fn add(a: i32, b: i32) -> i32 {
    a + b // no semi-colon here!
}
5
7