Questions

Rust questions

Choose a question page, learn the concept, then test your understanding with a quiz.

Returning Strings and &str from Functions in Rust

Learn when Rust functions should return String, &str, or &'static str, and how ownership and lifetimes keep returned text safe.

rust

Returning Values vs References from Functions in Rust

Learn why Rust functions usually return owned values instead of references to local variables, with file handling examples using File and OpenOptions.

rustreferencelifetime

Reverse for Loops in Rust: Iterating from 100 Down to 1

Learn how to write reverse for loops in Rust, including descending ranges, rev(), inclusive ranges, and common pitfalls.

rustfor-loop

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

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.

rustsyntax

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.

rustarraysperformancellvm-codegen

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.

rustreferencelanguage-lawyer

Rust Borrow Checker: Immutable and Mutable Borrows of a Graph

Learn why Rust rejects mutable borrows while references exist, how lifetimes protect memory safety, and practical ways to fix E0502.

rustreference

Rust Cargo Release Builds with Debug Information

Learn how to create optimized Rust Cargo release builds with debug symbols for meaningful profiling, debugging, and stack traces.

rustrust-cargo

Rust Copy and Clone for Enums Containing String

Learn why Rust enums containing String cannot implement Copy, how Clone works, and how to design safe ownership-aware enum types.

rust

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.

rust

Rust Crate Attributes: Where to Add #![feature(...)]

Learn what Rust crate attributes are, where they belong in main.rs or lib.rs, and how nightly feature gates differ from stable Rust.

rustrust-cargo

Rust E0554: Stable vs Nightly Features When Installing Cargo Packages

Learn why Rust error E0554 occurs during cargo install, how stable and nightly toolchains differ, and how to diagnose dependency features.

rustrust-cargo

Rust HashMap Entry API: Lookup or Insert Efficiently

Learn how to lookup or insert values in a Rust HashMap efficiently using the Entry API, with examples and common mistakes.

rusthashmaplookup

Rust Higher-Ranked Trait Bounds: for<> vs Regular Lifetime Bounds

Learn how Rust's for<> higher-ranked trait bounds differ from ordinary lifetime parameters, with trait object and closure examples.

rustsyntax

Rust Lifetimes Explained: What 'a, 'r, and 'static Mean

Learn what Rust lifetimes like 'a, 'r, and 'static mean, why the apostrophe matters, and how lifetimes work with references.

rust

Rust Modulus vs Remainder: How to Get True Modulo with Negative Numbers

Learn the difference between remainder and modulus in Rust, why % is not true modulo, and how to get positive modulo results safely.

rustmodulo

Rust Multiline String Literals: Syntax, Raw Strings, and Line Breaks

Learn Rust multiline string literal syntax, including normal and raw strings, line breaks, escapes, and common mistakes beginners make.

ruststringsyntax

Rust Option Overhead: Memory Layout, Box, and Null Pointer Optimization

Learn when Rust Option has zero memory overhead, how Option<Box<T>> represents None, and what dereferencing costs in linked lists.

rustperformancenull-pointer

Rust Option: Understanding Some and None from get()

Learn why Rust get() returns Option with Some or None, how it prevents out-of-bounds errors, and when to use safe access or indexing.

rustoption-type

Page 6 of 9 - 162 questions