Questions
Rust questions
Choose a question page, learn the concept, then test your understanding with a quiz.
Store Closures in Structs in Rust: Generics, FnMut, and Trait Objects
Learn how to store Rust closures in structs using generic FnMut bounds, trait objects, lifetimes, and function pointers with practical examples.
Switch Between Rust Toolchains with rustup
Learn how to switch Rust toolchains with rustup defaults, directory overrides, rust-toolchain files, and one-command selections.
Understanding Cargo Registry Locking in Rust: Why `cargo build` Waits for a File Lock
Learn why Rust Cargo shows "Blocking waiting for file lock on the registry index" on macOS and how to diagnose and fix it safely.
Understanding Rust Modules with main.rs and lib.rs
Learn how Rust module lookup works with main.rs and lib.rs, why crate::foo fails, and how to organize binary and library crates correctly.
Understanding dyn Trait Objects in Rust
Learn what dyn means in Rust types, how trait objects work, and when to use &dyn Trait or Box<dyn Trait> for dynamic dispatch.
Understanding “Cannot Move Out of Borrowed Content” in Rust
Learn why Rust shows “cannot move out of borrowed content”, how ownership and borrowing interact, and how to fix it safely.
Using macro_rules! Across Module Files in Rust
Learn how to use macro_rules! macros across module files in Rust, including #[macro_use], #[macro_export], scope rules, and practical examples.
What Are Non-Lexical Lifetimes in Rust?
Learn what non-lexical lifetimes are in Rust, how they improve borrowing, and why the borrow checker became more flexible.
What Is a Fat Pointer in Rust? Slices, Trait Objects, and Why They Are Larger
Learn what fat pointers are in Rust, why they are larger than normal pointers, and how slices and trait objects use them.
What Rust Uses Instead of a Garbage Collector
Learn how Rust frees memory without a garbage collector using ownership, scope, and Drop, and how this differs from typical GC systems.
What `let fields = fields;` Does in Rust
Learn what `let x = x;` means in Rust, how shadowing works, and why developers use `let fields = fields;` in real Rust code.
When Rust Closures Implement Fn, FnMut, and FnOnce
Learn when Rust closures implement Fn, FnMut, and FnOnce, how capture behavior affects each trait, and how to choose the right bound.
When to Use #[inline], #[inline(always)], and #[inline(never)] in Rust
Learn when to use Rust inline attributes, what they actually mean, and when #[inline], #[inline(always)], or #[inline(never)] help or hurt.
Why Capitalizing the First Letter of a String Is Different in Rust
Learn why Rust string capitalization is tricky, why &str cannot be indexed, and the simplest safe ways to uppercase the first letter.
Why Explicit Lifetimes Are Needed in Rust
Learn why Rust needs explicit lifetimes, when inference is enough, and when lifetime annotations are required for safe references.
Why Rust Avoids &String, &Vec, and &Box in Function Arguments
Learn why Rust functions usually take &str, slices, or plain references instead of &String, &Vec, and &Box, with examples and best practices.
Why Rust Cannot Store a Value and a Reference to It in the Same Struct
Learn why self-referential structs fail in Rust, what lifetime errors mean, and practical ways to model owned data safely.
Why Rust Executables Are So Large: Understanding Binary Size in Rust
Learn why Rust binaries can seem large, what gets included in a build, and how debug, release, stripping, and panic settings affect size.
Why Rust May Not Optimize Non-Aliasing Mutable References Yet
Learn why Rust mutable references imply no aliasing, why LLVM may still avoid some optimizations, and how this relates to UB and codegen.
Why You Can't Index a String in Rust and How to Access Characters Safely
Learn why Rust strings cannot be indexed by number and how to access characters safely using chars, bytes, and iterators.