rust

Environment variables with std::env for configuration

Reading environment variables is a common way to configure applications. std::env::var("KEY") returns Result<String, VarError>, which you handle with ? or .unwrap_or_else(). I use env vars for secrets, runtime config, and feature flags. For pars

VecDeque<T> for double-ended queue operations

VecDeque&lt;T&gt; is a growable ring buffer supporting efficient push/pop from both ends. I use it for queues, breadth-first search, and sliding windows. Methods: .push_front(), .push_back(), .pop_front(), .pop_back() are all O(1). It's implemented as

axum for type-safe async HTTP servers

Axum is a modern web framework built on tokio and hyper. It uses extractors (like Json&lt;T&gt;, Path&lt;T&gt;, State&lt;S&gt;) to parse requests into Rust types, and the compiler ensures your handlers match their routes. Middleware is just functions,

tokio::select! for racing multiple async operations

Tokio's select! macro lets you wait on multiple futures simultaneously, proceeding with the first one that completes. I use it for timeouts, graceful shutdown, and racing I/O operations. Each branch is a pattern match on the future's output. If multip

Criterion for benchmarking with statistical analysis

Criterion is the standard benchmarking library for Rust. It runs benchmarks multiple times, detects outliers, and reports statistical confidence intervals. The API is simple: wrap your code in a closure, and criterion measures execution time. It gener

Trait bounds for generic functions with behavior constraints

Traits define shared behavior, and trait bounds let you write generic functions that work with any type implementing a trait. The syntax T: Display means "T must implement Display." This is similar to interfaces in other languages but more powerful: y

reqwest for async HTTP client with connection pooling

Reqwest is the most popular async HTTP client for Rust. It's built on tokio and hyper, with a high-level API for making requests. Connection pooling, redirects, timeouts, and TLS are handled automatically. I use the builder pattern to configure client

Custom error types with thiserror for domain errors

For production code, I define custom error enums using thiserror. It auto-derives Display and Error trait implementations, making errors self-documenting and composable. Each variant can wrap underlying errors (#[from]) for automatic conversion with ?

AsRef and AsMut for flexible function parameters

AsRef&lt;T&gt; is a trait for cheap reference-to-reference conversion. It's commonly used in function parameters to accept multiple types. For example, a function taking impl AsRef&lt;Path&gt; can accept &amp;Path, PathBuf, &amp;str, or String. This i

wasm-bindgen for Rust to JavaScript interop in WebAssembly

Wasm-bindgen generates JavaScript bindings for Rust code compiled to WebAssembly. Annotate functions with #[wasm_bindgen], and the tool generates JS glue code. I use it to write performance-critical browser code in Rust: parsers, crypto, data processi

Unsafe Rust for FFI and low-level optimizations

Unsafe Rust lets you bypass some of the compiler's safety checks when necessary. Common uses include FFI (calling C code), dereferencing raw pointers, and implementing low-level data structures. The unsafe keyword creates a boundary where you promise

Tower middleware for composable HTTP service layers

Tower is a library of modular middleware (called "layers") for async services. Axum is built on Tower, so you can use any Tower middleware: TimeoutLayer, CompressionLayer, TraceLayer, etc. Layers wrap services, adding behavior like logging, metrics, o