0
0
Rustprogramming~10 mins

Generic enums in Rust - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a generic enum with one type parameter.

Rust
enum Option<T> {
    Some(T),
    [1],
}
Drag options to blanks, or click blank then click option'
ANone
BNothing
CEmpty
DNull
Attempts:
3 left
💡 Hint
Common Mistakes
Using variant names like 'Nothing' or 'Null' which are not valid in Rust's Option enum.
2fill in blank
medium

Complete the code to create a generic enum with two type parameters.

Rust
enum Result<T, E> {
    Ok(T),
    [1](E),
}
Drag options to blanks, or click blank then click option'
AError
BErr
CFail
DFailing
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Error' or 'Fail' which are not the correct variant names.
3fill in blank
hard

Fix the error in the generic enum definition by completing the missing variant name.

Rust
enum Either<L, R> {
    Left(L),
    [1](R),
}
Drag options to blanks, or click blank then click option'
ASide
BWrong
COther
DRight
Attempts:
3 left
💡 Hint
Common Mistakes
Using variant names like 'Wrong' or 'Other' which are not standard.
4fill in blank
hard

Fill both blanks to define a generic enum with two variants holding different types.

Rust
enum Pair<T, U> {
    First([1]),
    [2](U),
}
Drag options to blanks, or click blank then click option'
AT
BV
CSecond
DThird
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variant names or wrong type parameters.
5fill in blank
hard

Fill all three blanks to define a generic enum with three variants holding different types.

Rust
enum Triple<A, B, C> {
    First([1]),
    Second([2]),
    [3](C),
}
Drag options to blanks, or click blank then click option'
AA
BB
CThird
DFourth
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variant names or mismatching types.