fn main() println!("Hello, Rust!");
| Concept | Syntax / Rule | |---------|----------------| | Immutable var | let x = 5; | | Mutable var | let mut x = 5; | | Function | fn add(a: i32, b: i32) -> i32 a + b | | Ownership move | let s2 = s1; (s1 invalid) | | Borrow reference | fn calc(&s: &String) | | Mutable borrow | &mut – only one at a time | | Option | match option Some(x) => ..., None => ... | | Error handling | result? inside Result -returning fn | | Lifetime | <'a> ties lifetimes of references | ultimate rust crash course
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: fn main() println
When a function returns a reference, the lifetime of the output must be tied to one of the inputs. It’s your friend