#+title: Learning Rust #+date: [2024-05-10 Fri] #+filetags: :programming:rust: #+identifier: 20240510T112034 * Why Rust? - Memory safety without garbage collection - Zero-cost abstractions - Fearless concurrency - Great tooling (cargo, clippy, rustfmt) * Ownership Rules 1. Each value has exactly one owner 2. When the owner goes out of scope, the value is dropped 3. You can have either one mutable reference or many immutable ones #+begin_src rust fn main() { let s1 = String::from("hello"); let s2 = s1; // s1 is moved, no longer valid println!("{}", s2); } #+end_src * The Borrow Checker The borrow checker enforces ownership rules at compile time. This eliminates entire classes of bugs: - Use-after-free - Double-free - Data races - Null pointer dereferences * Resources - [[https://doc.rust-lang.org/book/][The Rust Book]] — start here - [[https://doc.rust-lang.org/rust-by-example/][Rust by Example]] — hands-on - [[https://rustlings.cool/][Rustlings]] — small exercises