Questions

Rust questions

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

Rust Orphan Rule: Implementing Traits for External Types with Newtypes

Learn why Rust prevents implementing external traits for external types, and use the newtype pattern to overload operators safely.

rusttraits

Rust Package with Both a Library and a Binary

Learn how to structure a Rust package with both a reusable library and an executable using Cargo.toml, src/lib.rs, and src/main.rs.

rustrust-cargo

Rust Pointers Explained: Box, ref, References (&), and Raw Pointers (*)

Learn how Rust Box, ref patterns, references (&), dereferencing (*), and raw pointers work with ownership, borrowing, and safe code.

rustpointers

Rust Queue and Stack Collections: Vec and VecDeque

Learn how to build efficient FIFO queues and LIFO stacks in Rust with Vec and VecDeque, including push, pop, front, and back examples.

rust

Rust Raw String Literals: What r#"..."# Means and How Interpolation Works

Learn what Rust raw string literals like r#"..."# do, why they help with JSON, and how to insert variable values correctly in Rust.

ruststringsyntaxstring-literals

Rust References: What & and * Mean

Learn what Rust's & and * operators mean, how borrowing and dereferencing work, and why &i32 and &mut i32 behave differently with +.

rustsyntaxreferencedereference

Rust String vs str: Differences, Uses, and When to Choose Each

Learn the difference between Rust `String` and `str`, when to use each, and how owned and borrowed string types work in practice.

ruststring

Rust Structs with Owned String Fields

Learn how to define and instantiate Rust structs with owned String fields, when to use String versus &str, and avoid lifetime issues.

ruststring

Rust Test-Only Dependencies with Cargo dev-dependencies

Learn how to add test-only Rust dependencies with Cargo dev-dependencies, including compiletest setup, behavior, examples, and common mistakes.

rustrust-cargo

Rust Trait Objects in Struct Fields: Box, References, Lifetimes, and self

Learn how Rust structs store trait implementations with dyn Trait, Box, and references, including lifetimes, ownership, and consuming self.

rusttraits

Rust Traits vs Haskell Typeclasses: Key Differences Explained

Learn the difference between Rust traits and Haskell typeclasses with examples, comparisons, and practical usage patterns.

rusthaskelltraits

Rust `iter()` vs `into_iter()`: Understanding Borrowed and Owned Iteration

Learn the difference between Rust `iter()` and `into_iter()`, including ownership, borrowing, arrays, vectors, and practical examples.

rustiterator

Rust `use` vs `extern crate`: What’s the Difference?

Learn the difference between Rust `use` and `extern crate`, why both existed, when to use them, and how modern Rust imports crates.

rust

Rust `usize` vs `u32`: What’s the Difference and When to Use Each

Learn the difference between Rust `usize` and `u32`, when each should be used, and why pointer-sized integers matter in real programs.

rust

Rust clone() vs to_owned(): What’s the Difference?

Learn the difference between clone() and to_owned() in Rust, including ownership, borrowed vs owned data, and practical string examples.

rust

Rust match Wildcard Arm: Do Nothing for Unmatched Strings

Learn how Rust's wildcard match arm handles unmatched strings with the unit value (), and when to use match, if let, or matches! safely.

rust

Rust mod.rs Files: Purpose, Modules, and Modern Alternatives

Learn what Rust mod.rs files do, how Rust modules map to files and folders, and why modern Rust projects usually prefer foo.rs.

rustmodule

Rust mut Before a Variable Name vs After the Colon Explained

Learn the difference between `mut foo: T` and `foo: &mut T` in Rust, with examples of mutable bindings versus mutable references.

rustvariablessyntaxreference

Rust unwrap() Explained: Using Result and Option Safely

Learn what unwrap() does in Rust, how it works with Result and Option, when to use it, and safer alternatives for error handling.

rusterror-handling

Safe and Idiomatic Numeric Type Conversion in Rust

Learn safe, idiomatic numeric conversions in Rust using casts, TryFrom, From, and pointer-sized types like usize and isize.

rustcastingnumbers

Page 7 of 9 - 162 questions