statement

Rust Expression statements and discarded values

Use a statement to perform an action without keeping its result. For example, a call may print a message and a calculation may be discarded. Expected output (not executed): Preparing () Why: The print runs; the sum is discarded and the block completes with unit. Common mistake: Do not assume every semicolon just separates lines; the final expression loses its role as the block result when terminated.

Formal Syntax & Structure

rust syntaxrust
expression;

Working Example

Example Snippetrust
fn main() {    let result = {        println!("Preparing");        7 + 2;    };    println!("{result:?}");}
Rust Reference