rust

Borrowing with & and &mut for zero-cost access

Instead of transferring ownership, Rust lets you borrow values with references (&T for immutable, &mut T for mutable). Borrows allow functions to read or modify data without taking ownership, so the caller retains access afterward. The borrow

tempfile for safe temporary file creation

The tempfile crate creates temporary files and directories that are automatically cleaned up on drop. I use it in tests, build scripts, and anywhere I need scratch space. tempfile::NamedTempFile gives you a file path, while tempfile::tempfile() create

HashSet<T> for unique value collections

HashSet&lt;T&gt; stores unique values with O(1) average-case membership tests. It's backed by a HashMap&lt;T, ()&gt;. I use it for deduplication, membership checks, and set operations (.union(), .intersection()). Common methods: .insert(v) adds, .cont

From and Into for type conversions

The From and Into traits provide a standard way to convert between types. Implementing From&lt;T&gt; for your type automatically provides Into&lt;T&gt; via a blanket implementation. I use From for infallible conversions (like String::from("hello")) an

std::fmt::Display for user-facing string representations

Implementing Display lets your types be formatted with {} in format strings. It's for user-facing output, unlike Debug which is for developers. I implement Display for error types, domain models, and anything that might be printed. The trait requires

Atomic operations for lock-free concurrency

For high-performance concurrent code, atomics provide lock-free synchronization. The std::sync::atomic module has AtomicBool, AtomicUsize, etc., with operations like load, store, fetch_add, and compare_exchange. These compile to CPU-level atomic instr

PhantomData for zero-cost type-level markers

PhantomData&lt;T&gt; is a zero-sized type that acts as if it owns T for the purposes of lifetimes, variance, and drop check. I use it in the typestate pattern or when a struct logically depends on T but doesn't store it. For example, a handle to an ex

Rayon for data parallelism with par_iter

Rayon makes data parallelism trivial: replace .iter() with .par_iter(), and your loop runs in parallel across all CPU cores. It uses a work-stealing scheduler to balance load automatically. I use rayon for CPU-bound tasks like image processing, data t

log crate facade for pluggable logging backends

The log crate provides logging macros (error!, warn!, info!, debug!, trace!) that are backend-agnostic. Libraries use log, and applications choose the backend (env_logger, simple_logger, or tracing). This decouples logging from the implementation. I u

Option<T> for explicit null handling

Rust has no null. Instead, Option&lt;T&gt; represents a value that might be absent. It's an enum with two variants: Some(T) and None. You must explicitly handle both cases with match, if let, or combinator methods like .map() and .unwrap_or(). This el

Iterator trait and combinators for zero-cost collection processing

Rust's Iterator trait provides a rich set of combinators (.map(), .filter(), .fold(), etc.) that compose without allocating intermediate collections. Iterators are lazy: they don't do work until you consume them with .collect(), .for_each(), or simila

Associated types in traits for cleaner generics

Associated types let a trait declare a type that implementors must define. This is cleaner than adding a generic parameter to the trait. For example, Iterator has an associated type Item rather than being Iterator&lt;Item&gt;. I use associated types w