Vehicle with variants Car, Bike, and Truckmy_vehicle and assign it the value Vehicle::Bikematch statement on my_vehicle with arms for each variant"It's a car!", "It's a bike!", or "It's a truck!"Vehicle with variants Car, Bike, and Truckmy_vehicle and assign it the value Vehicle::Bikematch statement on my_vehicle with arms for each variant"It's a car!", "It's a bike!", or "It's a truck!"Vehicle with three variants: Car, Bike, and Truck.Use the enum keyword followed by the name Vehicle. Inside curly braces, list the variants separated by commas.
my_vehicle and assign it the value Vehicle::Bike.Use let to create the variable and assign Vehicle::Bike to it.
match statement on my_vehicle with arms for each variant: Car, Bike, and Truck. For each arm, write a comment describing the vehicle type.Use match my_vehicle { Vehicle::Car => { }, Vehicle::Bike => { }, Vehicle::Truck => { } }.
match arm, use println! to print exactly: "It's a car!", "It's a bike!", or "It's a truck!" respectively.Use println!("It's a bike!"); inside the Vehicle::Bike arm, and similar for others.
What does the match statement do when used with enums in Rust?
match with enumsmatch statement compares the enum value against each variant.Which of the following is the correct syntax to match an enum Color with variants Red, Green, and Blue?
enum Color { Red, Green, Blue }Color::Red.Color::Variant syntax.What will be the output of this Rust code?
enum Direction { North, South, East, West }
fn main() {
let dir = Direction::East;
let message = match dir {
Direction::North => "Going up",
Direction::South => "Going down",
Direction::East => "Going right",
Direction::West => "Going left",
};
println!("{}", message);
}dir is set to Direction::East.dir to the correct messageDirection::East returns "Going right".Find the error in this Rust code snippet using match with enums:
enum Status { Success, Failure }
fn check(status: Status) {
match status {
Status::Success => println!("Success"),
// Missing Failure arm
}
}Status::Success but misses Status::Failure.Given this enum with data:
enum Message {
Quit,
Move { x: i32, y: i32 },
Write(String),
ChangeColor(i32, i32, i32),
}Which match arm correctly extracts the x and y values from Message::Move?
Move uses named fields { x: i32, y: i32 }.Message::Move { x, y } to destructure named fields directly.Pass the test and this pattern moves unknown