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

Inline assembly for critical performance hotspots

Rust's inline assembly (asm! macro) lets you write assembly for performance-critical code or to access hardware features. It's an unstable feature (nightly only) and requires unsafe. I use it sparingly for SIMD intrinsics not exposed by std::arch, cry

cfg attribute for conditional compilation

The #[cfg(...)] attribute enables conditional compilation based on features, target OS, or build profiles. I use #[cfg(test)] for test-only code, #[cfg(target_os = \"linux\")] for platform-specific logic, and #[cfg(feature = \"...\")] for optional fea

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