let some_number = Some(5); let absent_number: Option<i32> = None; // You cannot add Option<i32> to i32 directly. let x: i32 = 5; let y: Option<i32> = Some(10); // let sum = x + y; // ERROR: mismatched types
Immutability prevents accidental changes across large codebases. It’s your friend. Constants const MAX_POINTS: u32 = 100_000; // always immutable, type required. 4. Shadowing (Not Mutation) You can redeclare a variable name: ultimate rust crash course
pub trait Summary fn summarize(&self) -> String; let some_number = Some(5)
For quick prototyping: unwrap() or expect() (panics on error). let absent_number: Option<
Early return uses return keyword.