Lifetime annotations for flexible borrowing in structs

When a struct holds a reference, you must annotate its lifetime so the compiler knows the reference won't outlive the data. The syntax <'a> declares a lifetime parameter, and &'a str ties the reference to that lifetime. This ensures that as

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

Ownership transfer prevents double-free and use-after-free

Rust's ownership system guarantees memory safety without garbage collection. Each value has exactly one owner, and when ownership is transferred (moved), the previous owner can't use it anymore. This prevents double-frees and use-after-free bugs at co

anyhow::Context for adding error context without custom types

When prototyping or writing applications (not libraries), anyhow is my go-to. It provides Result<T> as an alias for Result<T, anyhow::Error>, which can hold any error type. The .context() method attaches additional context to errors as the

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 ?

Result and ? operator for clean error propagation

Rust's Result<T, E> forces you to handle errors explicitly, but the ? operator makes it ergonomic. When a function returns Result, using ? automatically returns early with the error if it's Err, or unwraps the value if it's Ok. This replaces ver