Challenge - 5 Problems
Enum Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of a simple enum match
What is the output of this Rust code?
Rust
enum Direction { North, South, East, West, } fn main() { let dir = Direction::East; match dir { Direction::North => println!("Going North"), Direction::South => println!("Going South"), Direction::East => println!("Going East"), Direction::West => println!("Going West"), } }
Attempts:
2 left
💡 Hint
Look at which enum variant is assigned to dir and which arm of match it triggers.
✗ Incorrect
The variable dir is set to Direction::East, so the match arm for Direction::East runs, printing "Going East".
🧠 Conceptual
intermediateEnum variant with data
Which enum variant declaration correctly holds a string value in Rust?
Attempts:
2 left
💡 Hint
Think about how Rust enums hold data inside variants.
✗ Incorrect
Option A correctly declares a variant Text that holds a String value. Other options use invalid syntax.
🔧 Debug
advancedFix the enum pattern matching error
What error does this Rust code produce?
Rust
enum Color { Red, Green, Blue, } fn main() { let c = Color::Red; match c { Color::Red => println!("Red"), Color::Green => println!("Green"), } }
Attempts:
2 left
💡 Hint
Check if all enum variants are covered in the match arms.
✗ Incorrect
The match does not cover Color::Blue, so Rust reports a non-exhaustive pattern error.
📝 Syntax
advancedIdentify the invalid enum declaration
Which enum declaration is invalid in Rust?
Attempts:
2 left
💡 Hint
Look at the syntax for enum variant declarations with and without data.
✗ Incorrect
Option B uses `Ok: u32` which is invalid syntax. Variants with data use parentheses, not colons.
🚀 Application
expertCount enum variants with data
Given this enum, how many variants hold data?
Rust
enum Event { Click { x: i32, y: i32 }, KeyPress(char), Resize, Close, }
Attempts:
2 left
💡 Hint
Look for variants that have parentheses or braces with fields.
✗ Incorrect
Click has named fields, KeyPress has a tuple field, so 2 variants hold data. Resize and Close hold none.
