Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a simple enum named Color.
Rust
enum [1] {
Red,
Green,
Blue
}Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase names for enums.
Adding spaces or invalid characters in the enum name.
✗ Incorrect
The enum name should be
Color starting with a capital letter as per Rust naming conventions.2fill in blank
mediumComplete the code to add a variant Yellow to the Color enum.
Rust
enum Color {
Red,
Green,
Blue,
[1]
}Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase variant names.
Using snake_case or camelCase instead of PascalCase.
✗ Incorrect
Enum variants in Rust start with a capital letter, so
Yellow is correct.3fill in blank
hardFix the error in the enum definition by completing the code.
Rust
enum Shape {
Circle(f64),
Rectangle[1](f64, f64),
}Attempts:
3 left
💡 Hint
Common Mistakes
Using snake_case for variant names.
Using lowercase letters at the start of variant names.
✗ Incorrect
Enum variants must be named with PascalCase, so
WidthHeight is correct.4fill in blank
hardFill both blanks to define an enum Message with variants Quit and Move that holds two i32 values.
Rust
enum [1] { Quit, [2](i32, i32), }
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase names for enum or variants.
Forgetting parentheses for variants holding data.
✗ Incorrect
The enum name is
Message and the variant is Move with capital letters.5fill in blank
hardFill all three blanks to define an enum Result with variants Ok holding a T and Error holding a E.
Rust
enum [1]<T, E> { [2](T), [3](E) }
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase names for enum or variants.
Missing generic parameters in enum definition.
✗ Incorrect
The enum is
Result with variants Ok and Error, all using PascalCase.