Rust
Rust delivers memory safety, fearless concurrency, and zero-cost abstractions for systems, WebAssembly, and embedded projects.
Keywords
- as, async, await, break, const, continue, crate, dyn, else, enum, extern
- false, fn, for, if, impl, in, let, loop
- match, mod, move, mut, pub, ref, return, self, Self
- static, struct, super, trait, true, type, unsafe, use, where, while, yield
Ownership & Borrowing
- Each value has a single owner; when owner goes out of scope, value drops.
- Immutable (`&T`) and mutable (`&mut T`) references enforce aliasing rules.
- Borrow checker ensures data races cannot compile.
- Smart pointers: Box, Rc, Arc, RefCell, Mutex control ownership semantics.
Language Features
- Pattern matching via `match`, `if let`, `while let`.
- Traits define shared behavior; generics are monomorphized.
- Macros (`macro_rules!` and procedural) generate code at compile time.
- Async/await integrates with executors like Tokio and async-std.
- Result and Option force explicit error handling.
Standard Library & Ecosystem
- std::collections (Vec, HashMap, BTreeMap), std::sync, std::fs, std::io.
- Cargo orchestrates builds, tests, benches, docs, and crates.io publishing.
- Tokio, Axum, Actix, Bevy, Tauri, and Yew power modern apps.
- Clippy lints; Rustfmt formats; Miri detects UB in const/code.
Operators
- Arithmetic: + - * / %
- Comparison: == != < > <= >=
- Logical: && || !
- Bitwise: & | ^ ! << >>
- Assignment: = += -= *= /= %= &= |= ^= <<= >>=
- Reference/dereference: &, &mut, *
Best Practices
- Use `?` to bubble up errors and `thiserror`/`anyhow` for ergonomics.
- Prefer iterators and combinators for functional pipelines.
- Gate unsafe blocks and justify with comments/tests.
- Run `cargo fmt`, `cargo clippy`, `cargo test`, and `cargo audit` in CI.