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

Rust function return value (integer i32)

  • return

  • i32

  • After an arrow -> we can add the type of the return value.

  • We can then return that value by using the return statement.

  • #[allow(clippy::needless_return)] is there to silence clippy, the linter.

fn main() {
    println!("{}", add(2, 3));
    println!("{}", add(3, 4));
}

fn add(x: i32, y: i32) -> i32 {
    #[allow(clippy::needless_return)]
    return x + y;
}