Attempt 100 Rust quiz questions to test your knowledge and improve your Rust skills. This Rust MCQ 2026 quiz helps beginners and learners practice important Rust concepts like ownership, borrowing, traits, lifetimes, Option, Result, error handling, etc.
100 Quiz To Learn Rust
Rust is one of the fastest-growing programming languages in the world, especially for system programming, backend development, and high-performance applications. If you want to test your Rust knowledge or prepare for coding interviews, this 100 Rust MCQ quiz will really help you.
Go through each Rust quiz question, try answering it yourself first, and then click on the dropdown button beside each question to find the correct answer and explanation.

Q1. What keyword is used to define a constant in Rust?
A. let
B. const
C. static
D. var
Show Answer
Answer: B
Constants in Rust are declared with const and must have a type.
Q2. What trait must a type implement to be printed using {} in Rust?
A. Debug
B. Display
C. Clone
D. PartialEq
Show Answer
Answer: B
Display is needed for formatting with {}.
Q3. Which Rust keyword is used to import modules or items?
A. include
B. import
C. use
D. mod
Show Answer
Answer: C
use brings modules or items into scope.
Q4. What is the output type of vec![1, 2, 3] in Rust?
A. Array
B. Slice
C. Vector
D. Tuple
Show Answer
Answer: C
Macro vec! creates a Vec (vector).
Q5. Which ownership rule states a value can have only one owner at a time?
A. Borrowing
B. Move semantics
C. Ownership
D. Lifetimes
Show Answer
Answer: C
Rust ownership enforces single ownership of values.
Q6. What does the mut keyword indicate in Rust?
A. Immutable variable
B. Mutable variable
C. Static lifetime
D. Reference type
Show Answer
Answer: B
mut makes a variable mutable.
Q7. Which type is returned by a function that never returns in Rust?
A. ()
B. i32
C. !
D. never
Show Answer
Answer: C
! is the never type for functions that don’t return.
Q8. What does the Option enum represent in Rust?
A. A result with error
B. A possible absence of a value
C. A vector type
D. A pointer type
Show Answer
Answer: B
Option indicates a value may be Some or None.
Q9. How do you handle errors with Result in Rust?
A. panic
B. unwrap or match
C. ignore
D. throw
Show Answer
Answer: B
Use unwrap or match to handle Result.
Q10. What is the default visibility of items in Rust modules?
A. public
B. private
C. crate
D. restricted
Show Answer
Answer: B
Items are private by default.
Q11. What type does &str represent in Rust?
A. Owned string
B. String literal slice
C. Integer
D. Dynamic array
Show Answer
Answer: B
&str is a string slice.
Q12. What loop construct executes repeatedly until broken in Rust?
A. for
B. while
C. loop
D. do-while
Show Answer
Answer: C
loop runs indefinitely unless broken.
Q13. What macro prints to standard output in Rust?
A. print!
B. println!
C. eprintln!
D. All of the above
Show Answer
Answer: D
All macros print output, with variations.
Q14. Which collection type stores key-value pairs in Rust?
A. Vec
B. HashMap
C. Option
D. Result
Show Answer
Answer: B
HashMap holds key-value pairs.
Q15. What does crate refer to in Rust?
A. Current package
B. Module inside function
C. External library
D. Debug trait
Show Answer
Answer: A
crate is the current package.
Q16. What is borrowing in Rust?
A. Moving ownership
B. Lending references without taking ownership
C. Cloning data
D. Deallocating memory
Show Answer
Answer: B
Borrowing gives references without ownership transfer.
Q17. Which keyword defines a module in Rust?
A. use
B. mod
C. crate
D. extern
Show Answer
Answer: B
mod declares a module.
Q18. What does unwrap() do on an Option?
A. Returns value or panics
B. Always returns None
C. Converts to Result
D. Clones value
Show Answer
Answer: A
unwrap() gives value or panics if None.
Q19. Which type ensures thread-safe shared ownership?
A. Rc
B. Arc
C. Box
D. Vec
Show Answer
Answer: B
Arc provides atomic reference counting.
Q20. What does Box do in Rust?
A. Stack allocation
B. Heap allocation
C. Macro definition
D. Trait implementation
Show Answer
Answer: B
Box stores data on the heap.
Q21. What keyword makes an item public in Rust?
A. pub
B. priv
C. public
D. export
Show Answer
Answer: A
pub makes items accessible externally.
Q22. How do you define a struct in Rust?
A. structure
B. struct
C. record
D. type
Show Answer
Answer: B
struct declares a custom data type.
Q23. What macro debug-prints a value with formatting?
A. println!
B. debug!
C. dbg!
D. trace!
Show Answer
Answer: C
dbg! prints with debug info.
Q24. Which operator dereferences a reference in Rust?
A. *
B. &
C. ->
D. ::
Show Answer
Answer: A
The * operator dereferences a reference.
Q25. What is the purpose of lifetimes in Rust?
A. Manage trait bounds
B. Manage variable scope
C. Ensure references are valid
D. Increase performance
Show Answer
Answer: C
Lifetimes ensure references don’t outlive data.
Q26. What does the keyword “fn” declare in Rust?
A. Variable
B. Function
C. Module
D. Trait
Show Answer
Answer: B
“fn” is used to declare a function.
Q27. What is the default integer type in Rust if you write 5?
A. i32
B. i64
C. u32
D. usize
Show Answer
Answer: A
Literal integers default to i32 unless otherwise specified.
Q28. Which loop is used to iterate over items in a collection?
A. loop
B. while
C. for
D. do-while
Show Answer
Answer: C
“for” loop is used to iterate over collections.
Q29. What does “match” provide in Rust?
A. Conditional branches
B. Pattern matching
C. Module imports
D. Variable definition
Show Answer
Answer: B
“match” provides pattern matching on values.
Q30. What type is returned by str.parse() when parsing to a number?
A. Option
B. Result
C. Vec
D. String
Show Answer
Answer: B
parse returns a Result for success or error.
Q31. Which attribute is used for testing functions in Rust?
A. test
B. #[test]
C. #[bench]
D. #[cfg]
Show Answer
Answer: B
#[test] marks a function as a test.
Q32. What does the “derive” attribute generate?
A. Functions
B. Trait implementations
C. Variables
D. Modules
Show Answer
Answer: B
derive auto-implements specified traits.
Q33. What type is used for dynamic dispatch in Rust?
A. Box
B. &T
C. &dyn Trait
D. Arc
Show Answer
Answer: C
&dyn Trait enables dynamic dispatch.
Q34. What keyword is used for external libraries in Rust?
A. link
B. extern
C. crate
D. mod
Show Answer
Answer: B
“extern” declares external dependencies.
Q35. What type uses non-null pointer optimization with Option?
A. Box
B. Vec
C. String
D. &str
Show Answer
Answer: A
Box
Q36. What keyword limits a generic type by capabilities?
A. bound
B. where
C. trait bound
D. restrict
Show Answer
Answer: C
Trait bounds constrain generic types.
Q37. Which type is used to allocate on the heap?
A. Rc
B. Vec
C. Box
D. Option
Show Answer
Answer: C
Box allocates data on the heap.
Q38. What does unwrap_or provide for Option?
A. Panic if None
B. Default value
C. Converts to Result
D. Clones
Show Answer
Answer: B
unwrap_or returns default if None.
Q39. What is a tuple in Rust?
A. Fixed collection of varied types
B. Dynamic array
C. Map type
D. String type
Show Answer
Answer: A
Tuple holds fixed heterogeneous elements.
Q40. What does “as” perform in Rust?
A. Dereference
B. Cast between types
C. Loop label
D. Import modules
Show Answer
Answer: B
“as” casts between compatible types.
Q41. What is a slice in Rust?
A. Fixed-size array
B. View into a sequence
C. Heap allocation
D. Module type
Show Answer
Answer: B
Slice is a view into a collection.
Q42. Which result variant indicates success?
A. Err
B. None
C. Ok
D. Some
Show Answer
Answer: C
Ok represents a successful Result.
Q43. What happens if you try to modify an immutable variable?
A. Panic at runtime
B. Compilation error
C. Runs silently
D. Converts to mutable
Show Answer
Answer: B
Immutable modification causes a compilation error.
Q44. What does “Vec::new” create?
A. Empty tuple
B. New vector
C. New map
D. New string
Show Answer
Answer: B
Vec::new initializes an empty vector.
Q45. What is pattern matching used for?
A. Error handling
B. Matching types
C. Deconstructing data
D. Dynamic dispatch
Show Answer
Answer: C
Pattern matching deconstructs data.
Q46. Which library provides collections like HashMap?
A. std::io
B. std::collections
C. std::fmt
D. std::ptr
Show Answer
Answer: B
std::collections contains HashMap and others.
Q47. What is a trait in Rust?
A. Type
B. Method
C. Interface-like behavior
D. Module
Show Answer
Answer: C
Trait defines shared behavior.
Q48. What does “unwrap_err” do on Result?
A. Returns Ok
B. Returns Err value or panics
C. Ignores errors
D. Converts to Option
Show Answer
Answer: B
unwrap_err returns error or panics if Ok.
Q49. What does “take” do on an Option?
A. Clones value
B. Takes value leaving None
C. Panics always
D. Converts to Result
Show Answer
Answer: B
take replaces with None returning old value.
Q50. What does “filter” do on an iterator?
A. Transforms elements
B. Keeps elements that satisfy a condition
C. Sorts elements
D. Removes duplicates
Show Answer
Answer: B
filter keeps items matching a predicate.
Q51. Which tool is used to manage Rust project dependencies and builds?
A. rustbuild
B. cargo
C. make
D. pom
Show Answer
Answer: B
Cargo is the Rust package manager and build tool.
Q52. Which keyword declares a Rust variable by default immutable?
A. mut
B. var
C. let
D. const
Show Answer
Answer: C
Let declares a variable that’s immutable unless mut is used.
Q53. Which symbol is used to borrow a reference in Rust?
A. *
B. &
C. !
D. ^
Show Answer
Answer: B
The ampersand & creates a reference borrow.
Q54. What collection is created with BTreeMap::new()?
A. Vector
B. HashMap
C. BTreeMap
D. Tuple
Show Answer
Answer: C
BTreeMap is a sorted key-value collection.
Q55. Which command compiles a Rust file?
A. rustc file.rs
B. gcc file.rs
C. compile file.rs
D. run file.rs
Show Answer
Answer: A
rustc compiles Rust source files.
Q56. Rust achieves memory safety without garbage collection using what?
A. Manual memory management
B. Runtime checks
C. Ownership and borrowing
D. Garbage collector
Show Answer
Answer: C
Rust uses ownership and borrowing to guarantee safety.
Q57. Which trait defines types that can be copied bitwise?
A. Clone
B. Copy
C. Default
D. Drop
Show Answer
Answer: B
The Copy trait allows bitwise duplication.
Q58. What feature allows functions to accept temporary reference parameters?
A. Ownership
B. Borrowing
C. Cloning
D. Lifetimes
Show Answer
Answer: B
Borrowing lets functions take references without owning.
Q59. What type is used for optional values in Rust?
A. None
B. Option
C. Result
D. Maybe
Show Answer
Answer: B
Option represents presence or absence of a value.
Q60. Which expression handles multiple cases in Rust?
A. ifelse
B. switch
C. match
D. choose
Show Answer
Answer: C
match enables pattern matching for control flow.
Q61. What does the Clone trait provide?
A. Shallow copy
B. Deep copy capability
C. Delete data
D. Borrow reference
Show Answer
Answer: B
Clone enables deep or explicit duplication.
Q62. What type handles success or error outcomes?
A. Option
B. Result
C. Either
D. Maybe
Show Answer
Answer: B
Result represents success or failure.
Q63. What is an enum in Rust?
A. A struct variant
B. A choice of variants
C. A function type
D. A trait
Show Answer
Answer: B
Enum represents a type with multiple variants.
Q64. What does the Drop trait allow?
A. Prevent compile
B. Custom cleanup
C. Faster execution
D. Debugging
Show Answer
Answer: B
Drop runs custom cleanup on scope exit.
Q65. What is the primary purpose of the cargo tool in Rust?
A. To compile programs
B. To manage project dependencies
C. To format code
D. To create new user accounts
Show Answer
Answer: B
Cargo handles dependency and build management for Rust projects.
Q66. How do you access the third element of a vector v?
A. v(2)
B. v[2]
C. v.get(2)
D. Both B and C
Show Answer
Answer: D
You can index or use get for safe access. :contentReference[oaicite:1]{index=1}
Q67. What does the “?” operator do in Rust?
A. Error checking
B. Multiplication
C. Unwrapping a value or propagating an error
D. Marks optional type
Show Answer
Answer: C
The ? operator propagates errors or unwraps success. :contentReference[oaicite:2]{index=2}
Q68. Which construct in Rust handles pattern matching on values?
A. ifelse
B. switch
C. match
D. loop
Show Answer
Answer: C
match provides comprehensive pattern matching. :contentReference[oaicite:3]{index=3}
Q69. What happens if you move a non-Copy type to another variable?
A. Deep copy
B. Value is cloned
C. Ownership is transferred
D. Borrowing occurs
Show Answer
Answer: C
Ownership moves to the new variable.
Q71. What does Rust’s standard library provide?
A. Only networking tools
B. Basic types and utilities
C. GUI components
D. Only trait definitions
Show Answer
Answer: B
The standard library includes types, I/O, threads, and more.
Q72. Which of these is a Rust loop construct?
A. do-while
B. until
C. loop
D. foreach
Show Answer
Answer: C
Rust supports the loop keyword as an infinite loop.
Q73. Which type represents an optional value?
A. Result
B. Maybe
C. Option
D. None
Show Answer
Answer: C
Option represents values that may or may not be present.
Q74. What is Rust’s default integer type?
A. i64
B. usize
C. i32
D. u128
Show Answer
Answer: C
Literal integers default to i32.
Q75. Which of these ensures memory safety without garbage collection?
A. Manual free
B. Garbage collector
C. Ownership and borrowing
D. Reference counting
Show Answer
Answer: C
Ownership and borrowing enforce safety at compile time.
Q76. What mechanism helps prevent dangling pointers?
A. Borrow checker
B. Garbage collector
C. Unsafe code
D. Foreach loop
Show Answer
Answer: A
The borrow checker ensures references remain valid.
Q77. What is a closure in Rust?
A. A loop
B. A trait
C. Anonymous function capturing environment
D. Type alias
Show Answer
Answer: C
Closures capture surrounding variables.
Q78. What is the purpose of lifetimes?
A. Improve speed
B. Ensure reference validity
C. Add traits
D. Manage threads
Show Answer
Answer: B
Lifetimes ensure references don’t outlive data.
Q79. Rust’s macro system executes at what time?
A. Runtime
B. Compile time
C. Link time
D. Execution time
Show Answer
Answer: B
Macros generate code at compile time.
Q80. Which type represents iterable collections?
A. Option
B. Iterator
C. Result
D. Box
Show Answer
Answer: B
The Iterator trait allows traversal of elements.
Q81. Which statement declares a mutable variable in Rust?
A. let x = 5
B. mut x = 5
C. let mut x = 5
D. var mut x = 5
Show Answer
Answer: C
Use “let mut” to declare a mutable variable in Rust.
Q82. What does “cargo run” do?
A. Runs tests
B. Builds and runs the project
C. Removes dependencies
D. Formats the code
Show Answer
Answer: B
“cargo run” compiles the project and runs the executable.
Q83. Which statement about Rust’s ownership is correct?
A. Multiple owners always allowed
B. Values have a single owner at a time
C. Ownership doesn’t matter
D. Rust uses garbage collection
Show Answer
Answer: B
Values in Rust have one owner at a time, enforced by the compiler.
Q84. What kind of functionality do Rust’s traits provide?
A. Memory allocation
B. Shared behavior definitions
C. Network sockets
D. Integer types
Show Answer
Answer: B
Traits allow defining common behavior for types.
Q85. What type is typically returned when parsing text to a number?
A. Result
B. Option
C. Vec
D. HashMap
Show Answer
Answer: A
Parsing via parse returns a Result.
Q86. Why does Rust not use a garbage collector?
A. It’s too slow
B. Rust uses ownership and borrowing for memory safety
C. Garbage collectors are illegal
D. Rust has no memory management
Show Answer
Answer: B
Ownership and borrowing provide memory safety without a GC.
Q87. What does the “dbg!” macro do?
A. Debug prints a value
B. Exits program
C. Allocates memory
D. Compiles code
Show Answer
Answer: A
dbg! prints debug information; helpful during development.
Q88. What keyword starts asynchronous functions?
A. async
B. await
C. future
D. spawn
Show Answer
Answer: A
async marks functions that return futures.
Q89. Which type represents a result that might fail?
A. Option
B. Result
C. Tuple
D. Box
Show Answer
Answer: B
Result encodes success or error outcomes.
Q90. What syntax is used to define an enum?
A. enum name { … }
B. struct name { … }
C. type name = …
D. trait name { … }
Show Answer
Answer: A
Enums are declared with enum and variants inside braces.
Q91. What does a closure capture?
A. Nothing
B. Variables from its environment
C. Errors
D. Traits
Show Answer
Answer: B
Closures capture surrounding variables.
Q92. Which file contains dependency info for a Rust project?
A. main.rs
B. Cargo.toml
C. config.json
D. package.json
Show Answer
Answer: B
Cargo.toml lists project details including dependencies.
Q93. What tool generates documentation from code comments?
A. rustdoc
B. cargo doc
C. fmt
D. test
Show Answer
Answer: A
rustdoc builds documentation from annotated comments.
Q94. What does the “await” keyword do?
A. Executes sync code
B. Waits for a future to finish
C. Declares a function
D. Allocates memory
Show Answer
Answer: B
await pauses until the future completes.
Q95. What collection holds key-value pairs?
A. Vec
B. HashMap
C. Option
D. Result
Show Answer
Answer: B
HashMap stores key-value associations.
Q96. What keyword is used to create a module in Rust?
A. crate
B. mod
C. use
D. extern
Show Answer
Answer: B
mod defines a new module in Rust.
Q97. Which feature allows code to run concurrently in Rust?
A. Threads
B. Garbage collector
C. Async/await
D. Both A and C
Show Answer
Answer: D
Rust supports threads and async/await for concurrency.
Q98. What does the “unsafe” keyword allow?
A. Safer code
B. Bypass safety checks
C. Faster compilation
D. Garbage collection
Show Answer
Answer: B
unsafe lets you bypass some of Rust’s safety guarantees.
Q99. Rust’s ownership model enforces what rule?
A. Multiple owners allowed
B. Only one owner per value
C. No borrowing allowed
D. Only static data
Show Answer
Answer: B
Each value has a single owner at any one time.
Q100. Which type does “String” represent?
A. Immutable string slice
B. Owned, growable UTF-8 string
C. Integer sequence
D. Character array
Show Answer
Answer: B
String is an owned, growable UTF-8 string.
Conclusion
I hope this Rust MCQ collection helped you practice important Rust concepts and improve your coding skills. Solving Rust quiz or programming quiz regularly is a great way to prepare for coding interviews, competitive exams, online tests, etc.
You can also continue your preparation with these Rust interview questions and answers that cover real interview-asked questions.
Resources and References:
- Rust Standard Library Documentation – https://doc.rust-lang.org/std/
- Rust by Example – https://doc.rust-lang.org/rust-by-example/
- Rustlings (Practice Exercises) – https://github.com/rust-lang/rustlings
- Reddit Rust Community – https://www.reddit.com/r/rust/
- Rust Compiler Reference Docs – https://rustc-dev-guide.rust-lang.org/





