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.

Setup

rustup, cargo, rustc, stable / nightly, targets. Bootstrapping a project.

Setup
Tooling

cargo, rustfmt, clippy, cargo-audit, cargo-watch, cargo-expand, cargo-flamegraph, miri.

Tooling
Snippets

Iterator combinators, ? error propagation, serde_json round-trips, std::fs shortcuts.

Snippets

Language#

The spec building blocks.

Syntax

//, /* */, ;, true false (None), attributes (#[...]). Comments, identifiers, keywords, literals.

Syntax
Variables

let, let mut, const, static, shadowing, destructuring, let-else.

Variables
Types

i8 u8 i32 u32 i64 u64 usize isize, f32 f64, bool, char, String, &str, tuples, arrays, slices, references.

Types
Operators

+ - * / %, == != < >, && || !, & | ^ << >>, & *, ?. Arithmetic, logical, bitwise, reference, try.

Operators
Controls

if, match, for, while, loop, break continue return, if let, while let, let-else.

Control flow
Functions

fn, ->, closures (|x|), generics, lifetimes, async fn, trait methods, impl Trait.

Functions
OOP

struct, enum, impl, trait, Self, associated types, blanket impls, trait objects (dyn).

OOP

Patterns#

The layer above the spec.

Patterns

Newtype, type-state, builder, RAII, From / Into, AsRef, the iterator pattern, error enums.

Patterns
Errors

Result<T, E>, ?, Option<T>, thiserror, anyhow, panic!, unwrap, expect.

Errors

Data Structures#

The container catalog.

Structures

Vec<T>, HashMap<K,V>, BTreeMap<K,V>, HashSet<T>, VecDeque<T>, Box, Rc, Arc, RefCell.

Data Structures
Algorithms

Iterator (map filter fold collect), sort, binary_search, itertools, rayon for parallel.

Algorithms

I/O#

Talking to files, the network, the shell, and the OS.

I/O

std::fs, std::io, BufReader, BufWriter, println!, serde_json, bincode.

I/O
CLI

std::env::args, clap, std::process::exit, stdin / stdout streaming.

CLI
Networking

std::net, tokio, reqwest, hyper, tonic (gRPC), rustls (TLS), tokio-tungstenite (WS).

Networking
Concurrency

std::thread, Send, Sync, Mutex, Arc, channels, async / await, tokio, rayon.

Concurrency

Runtime#

The compiler, cargo, and what happens between source and the binary.

Runtime

rustc, cargo build, Cargo.toml, Cargo.lock, editions, crates, modules, no_std, cross-compilation, MIR, LLVM.

Runtime

Ecosystem#

The standard library, crates.io, and the third-party catalog.

Libraries

Stdlib: std::collections, std::io, std::sync. Crates: serde, tokio, reqwest, clap, thiserror, anyhow, regex.

Libraries
Frameworks

Web: axum, actix-web, rocket. CLI: clap. Async: tokio, async-std. GUI: egui, tauri. eBPF: aya.

Frameworks

Practice#

The disciplines that make ownership shippable.

Testing

#[test], cargo test, doc tests, proptest, cargo-fuzz, criterion benchmarks.

Testing
Projects

End-to-end Rust projects: a scanner, a small async API, an eBPF probe (aya), a CLI tool.

Projects