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