Rust#
Rust is the operator’s language for code that must be fast, correct, and ship without a runtime. Statically typed, compiled, with ownership and borrow checking that eliminates whole classes of memory bugs at compile time. The same target space as C (systems, embedded, kernel modules, payloads) without the foot-cannons.
For the operator, Rust is the natural choice for new tools that
talk to the kernel (eBPF programs via aya, drivers,
implants), high-throughput services, parsers, and anything where
a memory bug is also a vulnerability.
Baseline. Rust 1.78+ is assumed. Edition 2021 by default;
recipes use modern features (let-else, async fn in
traits, GATs where they earn their keep).
Default toolchain. rustup for installing toolchains,
cargo for build / test / lint / doc, rustfmt for
formatting, clippy for linting, cargo audit for known
CVE scanning, cargo flamegraph for profiling.
Setup#
Picking a toolchain and getting cargo on the host.
rustup, cargo, rustc, stable /
nightly, targets. Bootstrapping a project.
cargo, rustfmt, clippy, cargo-audit,
cargo-watch, cargo-expand, cargo-flamegraph,
miri.
Iterator combinators, ? error propagation,
serde_json round-trips, std::fs shortcuts.
Language#
The spec building blocks.
//, /* */, ;, true false (None),
attributes (#[...]). Comments, identifiers,
keywords, literals.
let, let mut, const, static, shadowing,
destructuring, let-else.
i8 u8 i32 u32 i64 u64 usize isize, f32 f64,
bool, char, String, &str, tuples,
arrays, slices, references.
+ - * / %, == != < >, && || !,
& | ^ << >>, & *, ?. Arithmetic, logical,
bitwise, reference, try.
if, match, for, while, loop,
break continue return, if let, while let,
let-else.
fn, ->, closures (|x|), generics,
lifetimes, async fn, trait methods, impl Trait.
struct, enum, impl, trait, Self,
associated types, blanket impls, trait objects (dyn).
Patterns#
The layer above the spec.
Newtype, type-state, builder, RAII, From / Into,
AsRef, the iterator pattern, error enums.
Result<T, E>, ?, Option<T>, thiserror,
anyhow, panic!, unwrap, expect.
Data Structures#
The container catalog.
Vec<T>, HashMap<K,V>, BTreeMap<K,V>,
HashSet<T>, VecDeque<T>, Box, Rc,
Arc, RefCell.
Iterator (map filter fold collect),
sort, binary_search, itertools,
rayon for parallel.
I/O#
Talking to files, the network, the shell, and the OS.
std::fs, std::io, BufReader, BufWriter,
println!, serde_json, bincode.
std::env::args, clap, std::process::exit,
stdin / stdout streaming.
std::net, tokio, reqwest, hyper,
tonic (gRPC), rustls (TLS), tokio-tungstenite
(WS).
std::thread, Send, Sync, Mutex,
Arc, channels, async / await, tokio,
rayon.
Runtime#
The compiler, cargo, and what happens between source and the
binary.
rustc, cargo build, Cargo.toml,
Cargo.lock, editions, crates, modules,
no_std, cross-compilation, MIR, LLVM.
Ecosystem#
The standard library, crates.io, and the third-party catalog.
Stdlib: std::collections, std::io,
std::sync. Crates: serde, tokio,
reqwest, clap, thiserror, anyhow,
regex.
Web: axum, actix-web, rocket. CLI:
clap. Async: tokio, async-std. GUI:
egui, tauri. eBPF: aya.
Practice#
The disciplines that make ownership shippable.
#[test], cargo test, doc tests, proptest,
cargo-fuzz, criterion benchmarks.
End-to-end Rust projects: a scanner, a small async API,
an eBPF probe (aya), a CLI tool.