Questions

Rust questions

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

Absolute Values in Rust: Using the abs() Method

Learn how to calculate absolute values in modern Rust with abs(), handle signed integer overflow, and choose safer alternatives.

rust

Accepting Iterators in Rust Functions with impl Iterator

Learn how to write Rust functions that accept HashMap iterators using generic bounds or impl Iterator, avoiding trait object and lifetime errors.

rustfunctioniterator

Access Enum Variant Values in Rust with Pattern Matching

Learn how to extract and print values stored in Rust enum variants using match and if let pattern matching, with practical examples.

rust

Accessing Cargo Package Metadata in Rust

Learn how to read Cargo package metadata like version, name, and authors in Rust using compile-time environment macros.

rustrust-cargo

Associated Types vs Generic Type Parameters in Rust: When to Use Each

Learn when to use associated types vs generic parameters in Rust traits, with clear rules, examples, and practical API design advice.

rusttypesidioms

Automatically Recompile Rust Files with Cargo Watch

Learn how Cargo rebuilds changed Rust code and how cargo-watch automatically runs cargo check, build, test, or run when files change.

rustrust-cargo

Binary-Only Dependencies in Rust Cargo

Learn how to keep Rust library dependencies light by using optional Cargo dependencies, features, required-features, or separate packages.

rustrust-cargo

Can a Struct Extend Another Struct in Rust? Composition vs Inheritance

Learn how Rust handles struct reuse without inheritance, using composition, traits, and wrapper structs with practical examples.

rustinheritancestruct

Check Whether a String Contains a Substring in Rust

Learn how to check whether a Rust string contains a substring using str::contains, with examples, pitfalls, and practical patterns.

ruststring

Check Whether a Vec Contains a Value in Rust

Learn how to check whether a Rust Vec contains a value using contains and iterator methods, with examples, pitfalls, and practical patterns.

rust

Clone a Vector in a Generic Rust Function

Learn the idiomatic Rust way to clone a slice or vector in a generic function, mutate the copy, and return a new owned Vec<T>.

rust

Compare Rust Enums Without Verbose Pattern Matching

Learn how to compare Rust enum variants with PartialEq and matches!, including iterator filters, borrowed values, and common pitfalls.

rustenumspattern-matching

Concise HashMap Initialization in Rust

Learn concise, declarative ways to initialize Rust HashMaps using arrays, iterators, collect, HashMap::from, and counting patterns.

rusthashmap

Convert &str to &[u8] in Rust

Learn how to convert a Rust &str into a &[u8] with as_bytes(), why the types differ, and how UTF-8 affects byte slices.

ruststringslice

Convert C Strings to Rust Strings and Back with Rust FFI

Learn to safely convert null-terminated C strings to Rust strings and create C strings for Rust FFI using CStr and CString.

rustcffi

Convert Option<String> to Option<&str> in Rust

Learn the idiomatic Rust way to convert Option<String> into Option<&str> using as_deref, as_ref, and unwrap_or without extra allocation.

rust

Convert PathBuf to String in Rust Safely

Learn how to convert PathBuf to String in Rust, when conversion can fail, and safer alternatives for paths and file APIs.

ruststringdirectorypath

Convert Result to Option in Rust with ok()

Learn how to convert Rust Result values into Option with ok(), use filter_map for parsing, and choose when errors should be ignored or handled.

rustoption-type

Convert a Rust Enum to a User-Facing String

Learn how to convert Rust enum variants into user-facing strings with Display, string-returning methods, and practical formatting patterns.

rust

Convert a String to a Vector of Bytes in Rust

Learn how to convert Rust strings into Vec<u8> with as_bytes, to_vec, and into_bytes, including UTF-8 behavior and ownership rules.

rusttype-conversion

Page 1 of 9 - 162 questions

PreviousNext