Complete the code to define an enum variant with a single integer value.
enum Message {
Quit,
Move [1] i32,
}The enum variant Move holds a single i32 value, so it needs parentheses () around the data.
Complete the code to create an enum variant that holds two values: an integer and a boolean.
enum Status {
Active(i32, [1]),
Inactive,
}String or other types instead of bool for boolean data.The Active variant holds an i32 and a bool value, so the second type must be bool.
Fix the error in the enum variant definition that holds a named field.
enum Shape {
Circle [1] radius: f64,
Square { side: f64 },
}Named fields in enum variants require curly braces {} around the fields.
Fill both blanks to define an enum variant with named fields for width and height.
enum Rectangle {
Rect [1] width: u32, [2] height: u32 },
}The variant uses curly braces {} to start named fields, and fields are separated by commas ,.
Fill all three blanks to create a function that matches an enum with data and returns a string describing it.
fn describe(msg: Message) -> String {
match msg {
Message::Quit => String::from("Quit"),
Message::Move [1] x, y [2] => {
format!("Move to ([3], {})", x, y)
}
}
}The Move variant pattern uses parentheses ( ) to hold the two values x and y, separated by a comma.
