mod and pub for code organization and visibility

Rust's module system uses mod to define modules and pub to control visibility. Modules can be inline (mod name { ... }) or in separate files (mod name; loads name.rs). By default, items are private; use pub to expose them. I organize code into modules

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

BufReader and BufWriter for efficient I/O buffering

BufReader and BufWriter wrap readers/writers with an in-memory buffer, reducing system calls. For example, reading a file line-by-line with BufReader::new(file).lines() is much faster than unbuffered reads. I use them for parsing large files, log proc

File I/O with std::fs for reading and writing files

Rust's std::fs module provides file I/O. fs::read_to_string() reads a file into a String, fs::write() writes bytes. For larger files or streaming, use File::open() and BufReader/BufWriter for buffered I/O. Always handle errors with Result and ?. For p

Cow for clone-on-write to avoid unnecessary allocations

Cow<'a, T> (clone on write) holds either a borrowed or owned value. It borrows when possible and clones only when mutation is needed. I use Cow<str> for APIs that might need to modify a string: if no changes are needed, it stays borrowed;

String vs &str for owned vs borrowed text

String is an owned, growable UTF-8 string on the heap. &str is a borrowed string slice, often a view into a String or a string literal. I use String when I need to own, modify, or build strings. I use &str for function parameters (accepting bo

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

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

HashMap<K, V> for key-value lookups

HashMap&lt;K, V&gt; provides O(1) average-case lookups, inserts, and deletes. Keys must implement Hash + Eq. I use it for caches, indexing, and associative data. Common methods: .insert(k, v) adds/updates, .get(&amp;k) returns Option&lt;&amp;V&gt;, .r

Vec<T> for growable arrays with owned data

Vec&lt;T&gt; is Rust's dynamic array, stored on the heap. It grows as needed, amortizing allocations. I use Vec for collections of owned data, return values, and when you don't know the size upfront. Common methods: .push() appends, .pop() removes the

Default trait for sensible zero values

The Default trait provides a default value for a type, useful for builder patterns, config merging, and initialization. I derive Default on structs where zero/empty is meaningful. For custom logic, implement it manually. Default::default() is the stan

Drop trait for custom cleanup logic

The Drop trait runs when a value goes out of scope, similar to destructors in C++. I implement Drop for resource handles: closing file descriptors, releasing locks, or logging cleanup. The drop method takes &amp;mut self and can't fail (no Result). Ru