Topic
Statements & Expressions
Every line of Rust is either a statement (does something, returns nothing) or an expression (evaluates to a value). The semicolon is the switch between them.
Quick Reference
ConceptWhat it means
StatementA line that ends with ; and returns nothing
ExpressionA line that evaluates to a value, no semicolon
;Turns an expression into a statement, discards its value
{ }A block of code, returns the value of its last expression
()The unit type, what you get when a block or function returns nothing
TermWhat it meansWhen you use it
StatementA line that performs an action but produces no value, ends with ;Variable declarations, assignments, most lines of code
ExpressionA line that evaluates to a value, no semicolon at the endThe last line of a block or function that you want to return
;The semicolon, turns an expression into a statement and discards the valueAfter every line that does not return a value
{ }A block, can be an expression if its last line has no semicolonGrouping code; the last expression becomes the block's value
()The unit type, what you get when a semicolon discards an expressionReturn type of functions that return nothing