Questions
Rust questions
Choose a question page, learn the concept, then test your understanding with a quiz.
How to Import Modules from Another File in Rust Cargo Projects
Learn how to split Rust code into multiple files and import modules correctly in a Cargo project using mod and module paths.
How to Iterate Over a Range with a Custom Step in Rust
Learn how to loop over ranges with custom step sizes in Rust using iterators like step_by, with examples, pitfalls, and practice.
How to Iterate Through Enum Values in Rust
Learn how to iterate over enum values in Rust, why enums do not auto-list variants, and practical ways to loop through them safely.
How to Join a Vec<String> into One String in Rust
Learn how to join a Vec<String> into a single String in Rust using join(), with examples, pitfalls, and practical patterns.
How to Match a String in Rust: String vs &str in match Expressions
Learn how to match String values in Rust using &str, as_str(), and pattern matching with clear examples and common mistakes.
How to Print the Type of a Variable in Rust
Learn how to inspect and print a variable's type in Rust using std::any::type_name, with examples, caveats, and beginner-friendly guidance.
How to Return an Iterator in Rust
Learn the correct way to return iterators and trait types in Rust, including impl Iterator, trait objects, lifetimes, and common mistakes.
How to Set Default Values for Structs in Rust
Learn concise ways to initialize Rust structs with default values using constructors, the Default trait, and struct update syntax.
How to Split a String in Rust
Learn how to split strings in Rust using `split`, delimiters, patterns, and practical examples for parsing text safely.
How to Uninstall Rust Installed with rustup on Ubuntu
Learn how to uninstall Rust installed via rustup on Ubuntu, remove toolchains cleanly, and understand what rustup manages.
How to Update Cargo to the Latest Official Release in Rust
Learn how Cargo is updated in Rust, why Cargo and rustc versions can differ, and the correct way to get the latest stable release.
How to Use a Local Unpublished Crate in Rust
Learn how to use a local unpublished crate in Rust with Cargo path dependencies, Cargo.toml setup, and practical examples.
Idiomatic Callbacks in Rust: Fn, FnMut, FnOnce, and Box<dyn FnMut()>
Learn the idiomatic way to implement callbacks in Rust using Fn, FnMut, FnOnce, generics, and boxed trait objects.
Managing Object Lifetimes Safely in Rust Garbage Collector APIs
Learn how Rust lifetimes model heap-owned object validity and how to design safer garbage collector APIs with handles and borrowing.
Reading and Writing Files in Rust 1.x Without Panicking
Learn the idiomatic way to read and write files in Rust 1.x using Result, File, BufReader, and proper error handling.
Run System Commands and Capture Output in Rust
Learn how to execute system commands in Rust and capture stdout, stderr, and exit status using std::process::Command.
Rust ? Operator Explained: Error Propagation for Beginners
Learn what the `?` operator means in Rust, how it propagates errors, and when to use it with `Result` and `Option` values.
Rust Array Loop Performance: Why Size Changes Can Affect Optimization
Learn why Rust array loop performance can change with size, and how compiler optimizations like unrolling and constant folding affect timing.
Rust Auto-Dereferencing Rules in Method Calls Explained
Learn Rust's auto-dereferencing and auto-borrowing rules for method calls, including Deref, receiver lookup order, and common edge cases.
Rust Copy vs Clone: What’s the Difference?
Learn the difference between Copy and Clone in Rust, when each is used, and how ownership affects assignment and duplication.