Recall & Review
beginner Click to reveal answer
What is an enum in Rust?
An enum (short for enumeration) in Rust is a type that can be one of several different variants. It lets you define a type by listing possible values it can have.
beginner Click to reveal answer
How do you define a simple enum with three variants: Red, Green, Blue?
You write:
enum Color {
Red,
Green,
Blue
}intermediate Click to reveal answer
Can Rust enums hold data? Give an example.
Yes, Rust enums can hold data. For example:
enum Message {
Quit,
Move { x: i32, y: i32 },
Write(String),
ChangeColor(i32, i32, i32),
}This lets each variant carry different types and amounts of data.beginner Click to reveal answer
What keyword do you use to define an enum in Rust?
You use the keyword
enum followed by the name and variants inside curly braces.beginner Click to reveal answer
Why are enums useful in Rust?
Enums let you group related values under one type. They help write clear, safe code by handling different cases explicitly, like states or commands.Which keyword defines an enum in Rust?
✗ Incorrect
The keyword
enum is used to define enumerations in Rust.What does this enum variant represent?
Move { x: i32, y: i32 }✗ Incorrect
This variant holds two named fields, x and y, both integers.
Can Rust enums store different types of data in different variants?
✗ Incorrect
Rust enums can store different types and amounts of data in each variant.
Which of these is a valid enum variant name in Rust?
✗ Incorrect
Enum variant names conventionally start with a capital letter and use CamelCase.
What is the main benefit of using enums in Rust?
✗ Incorrect
Enums group related values and help handle different cases explicitly and safely.
Explain how to define an enum in Rust and give an example with at least three variants.
Start with the keyword enum, then list variants inside braces.
You got /4 concepts.
Describe how Rust enums can hold data and why this is useful.
Think about how each variant can carry its own information.
You got /4 concepts.
