Rust functions

From wikinotes
Revision as of 00:47, 7 February 2023 by Will (talk | contribs)

Function Signatures

fn main() {
    println!("hi");
}

Expressions vs Statements

  • statements include actions without a return value (ends in ;)
  • expressions include actions with a return value (no ;)

statement

{
    let y = 1;
    y += 1;
} // no return val

expression

let x = {
    let y = 1;
    y += 1       // <-- no semicolon
} // returns 2