let mut v = Vec::new(); v.push(1); v.push(2); let v2 = vec![1, 2, 3]; // macro
let home = IpAddrKind::V4(127,0,0,1); let loopback = IpAddrKind::V6(String::from("::1")); Rust has no null . Instead: Option<T> . ultimate rust crash course
Rust is famously loved for its memory safety, blazing speed, and excellent tooling. It’s also famously feared for its borrow checker and steep learning curve. This crash course strips away the complexity, giving you a mental model of Rust that works. let mut v = Vec::new(); v
| 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 | It’s also famously feared for its borrow checker