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:
enum Result<T, E> Ok(T), Err(E),
fn calculate_length(s: &String) -> usize // & means borrow s.len() // s goes out of scope, but nothing dropped (no ownership) fn main() { let s = String::from("hello"); let len = calculate_length(&s); println!("'{}' has length {}", s, len); // s still usable } fn change(s: &mut String) s.push_str(" world"); ultimate rust crash course
Traits are also used as on generics. 17. Lifetimes (The Scary Part – Made Simple) Lifetimes ensure references are always valid. Usually, the compiler infers them (lifetime elision). Sometimes you must annotate. // always immutable