Enums in Rust can have associated functions and methods, just like structs. These methods make it easier to encapsulate behavior directly within the enum.
In this challenge, you'll model the statuses of different vehicles and implement methods to describe their behavior.
Create an enum VehicleStatus with the following variants:
Parked — a unit variant representing a parked vehicle.Driving { speed: u32 } — a named field variant representing a vehicle driving at a certain speed.BrokenDown(String) — a tuple variant with a String describing the reason for the breakdown.Implement the following methods for VehicleStatus:
is_operational(&self) -> bool:
true if the vehicle is either Parked or Driving.false if the vehicle is BrokenDown.description(&self) -> String:
"The vehicle is parked." for Parked."The vehicle is driving at {speed} km/h." for Driving { speed }."The vehicle is broken down: {reason}." for BrokenDown(reason).match expression inside the methods to handle each variant.&self for the methods since they should not consume the enum.format! to construct strings with dynamic values, such as speed and reason.pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving { speed: u32 }, BrokenDown (String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self{ VehicleStatus::Parked => true, VehicleStatus::Driving { .. } => true, VehicleStatus::BrokenDown (_) => false } } pub fn description(&self) -> String { // Your code here... match self{ VehicleStatus::Parked => "The vehicle is parked.".to_string(), VehicleStatus::Driving { speed }=> format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown (reason) => format!("The vehicle is broken down: {reason}.") } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving{speed: u32}, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self { VehicleStatus::Parked => true, VehicleStatus::BrokenDown(_reason) => false, VehicleStatus::Driving{speed: _} => true, } } pub fn description(&self) -> String { // Your code here... match self { VehicleStatus::Parked => format!("The vehicle is parked."), VehicleStatus::Driving{speed} => format!("The vehicle is driving at {} km/h.", speed), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {}.", reason), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving{speed: u32}, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self { VehicleStatus::Parked => true, VehicleStatus::Driving{..} => true, VehicleStatus::BrokenDown(..) => false } } pub fn description(&self) -> String { // Your code here... match self { VehicleStatus::Parked => String::from("The vehicle is parked."), VehicleStatus::Driving{speed} => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}.") } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving{speed: u32}, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self { VehicleStatus::Parked => true, VehicleStatus::Driving{speed: _} => true, VehicleStatus::BrokenDown(_) => false } } pub fn description(&self) -> String { // Your code here... match self { VehicleStatus::Parked => String::from("The vehicle is parked."), VehicleStatus::Driving{speed} => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}.") } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving {speed : u32}, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self { VehicleStatus::Parked => true, VehicleStatus::Driving{..} => true, VehicleStatus::BrokenDown(_) => false, } } pub fn description(&self) -> String { // Your code here... match self { VehicleStatus::Parked => "The vehicle is parked.".to_string(), VehicleStatus::Driving{speed} => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}."), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving {speed : u32}, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self { VehicleStatus::Parked => true, VehicleStatus::Driving{..} => true, VehicleStatus::BrokenDown(_) => false, } } pub fn description(&self) -> String { // Your code here... match self { VehicleStatus::Parked => "The vehicle is parked.".to_string(), VehicleStatus::Driving{speed} => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}."), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving { speed: u32 }, BrokenDown(String)}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... if let VehicleStatus::BrokenDown(_) = self { false } else { true } } pub fn description(&self) -> String { // Your code here... match self { VehicleStatus::Parked => "The vehicle is parked.".into(), VehicleStatus::Driving { speed } => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}.") } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving { speed: u32 } , BrokenDown(String)}impl VehicleStatus { pub fn is_operational(&self) -> bool { match self { VehicleStatus::Parked => {true} VehicleStatus::Driving{speed} => {true} _ => {false} } } pub fn description(&self) -> String { // Your code here... match self { VehicleStatus::Parked => {"The vehicle is parked.".to_string()} VehicleStatus::Driving{speed} => {format!("The vehicle is driving at {speed} km/h.")} VehicleStatus::BrokenDown(reason) => {format!("The vehicle is broken down: {reason}.")} } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving { speed: u32 } , BrokenDown(String)}impl VehicleStatus { pub fn is_operational(&self) -> bool { match self { VehicleStatus::Parked => {true} VehicleStatus::Driving{speed} => {true} _ => {false} } } pub fn description(&self) -> String { // Your code here... match self { VehicleStatus::Parked => {"The vehicle is parked.".to_string()} VehicleStatus::Driving{speed} => {format!("The vehicle is driving at {speed} km/h.")} VehicleStatus::BrokenDown(reason) => {format!("The vehicle is broken down: {reason}.")} } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving { speed: u32 }, BrokenDown(String)}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self { VehicleStatus::Parked => {true} VehicleStatus::Driving{speed} => {true} _ => {false} } } pub fn description(&self) -> String { // Your code here... match self { VehicleStatus::Parked => {"The vehicle is parked.".to_string()} VehicleStatus::Driving{speed} => {format!("The vehicle is driving at {speed} km/h.")} VehicleStatus::BrokenDown(reason) => {format!("The vehicle is broken down: {reason}.")} } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving { speed: u32 }, BrokenDown(String)}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... // Alternative: //matches!(self, Self::Parked | Self::Driving { .. }) /* Another alternative: match self { Self::Parked | Self::Driving { .. } => true, _ => false } */ if let Self::Parked | Self::Driving { .. } = self { true } else { false } } pub fn description(&self) -> String { // Your code here... match self { Self::Parked => "The vehicle is parked.".to_string(), Self::Driving { speed } => format!("The vehicle is driving at {speed} km/h."), Self::BrokenDown(reason) => format!("The vehicle is broken down: {reason}.") } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { Parked, Driving { speed: u32 }, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { match self { Self::Parked => true, Self::Driving { speed: _ } => true, Self::BrokenDown(_) => false, } } pub fn description(&self) -> String { match self { Self::Parked => "The vehicle is parked.".to_string(), Self::Driving { speed } => { format!("The vehicle is driving at {speed} km/h.").to_string() } Self::BrokenDown(reason) => { format!("The vehicle is broken down: {reason}.").to_string() } } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving { speed: u32 }, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { match self { VehicleStatus::Parked => true, VehicleStatus::Driving { .. } => true, VehicleStatus::BrokenDown(_) => false, } } pub fn description(&self) -> String { match self { VehicleStatus::Parked => "The vehicle is parked.".to_string(), VehicleStatus::Driving { speed } => { format!("The vehicle is driving at {speed} km/h.") } VehicleStatus::BrokenDown(reason) => { format!("The vehicle is broken down: {reason}.") } } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { Parked, Driving{speed: u32}, BrokenDown(String)}impl VehicleStatus { pub fn is_operational(&self) -> bool { match self{ VehicleStatus::Parked | VehicleStatus::Driving{..} => true, VehicleStatus::BrokenDown(..) => false } } pub fn description(&self) -> String { match self{ VehicleStatus::Parked => format!("The vehicle is parked."), VehicleStatus::Driving{speed} => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(r) => format!("The vehicle is broken down: {r}.") } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving { speed: u32 }, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { !matches!(self, VehicleStatus::BrokenDown(_)) } pub fn description(&self) -> String { match self { VehicleStatus::Parked => "The vehicle is parked.".to_string(), VehicleStatus::Driving { speed } => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}."), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { Parked, Driving { speed: u32 }, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { match self { VehicleStatus::Parked | VehicleStatus::Driving { .. } => true, VehicleStatus::BrokenDown(_) => false, } } pub fn description(&self) -> String { match self { VehicleStatus::Parked => "The vehicle is parked.".into(), VehicleStatus::Driving { speed } => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}."), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving { speed: u32 }, BrokenDown(String)}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self { VehicleStatus::Parked | VehicleStatus::Driving { .. } => true, VehicleStatus::BrokenDown(_) => false } } pub fn description(&self) -> String { // Your code here... match self { VehicleStatus::Parked => String::from("The vehicle is parked."), VehicleStatus::Driving { speed } => format!("The vehicle is driving at {} km/h.", speed), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {}.", reason) } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving { speed: u32 }, BrokenDown(String)}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self { VehicleStatus::Parked|VehicleStatus::Driving{..} => true , VehicleStatus::BrokenDown(..) => false } } pub fn description(&self) -> String { // Your code here... match self { VehicleStatus::Parked => "The vehicle is parked.".to_string(), VehicleStatus::Driving { speed } => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}."), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { Parked, Driving{speed: u32}, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { match self { VehicleStatus::Parked | VehicleStatus::Driving{..} => true, VehicleStatus::BrokenDown(_) => false, } } pub fn description(&self) -> String { match self { VehicleStatus::Parked => "The vehicle is parked.".to_string(), VehicleStatus::Driving{speed} => format!("The vehicle is driving at {speed} km/h.").to_string(), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}.").to_string(), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving { speed: u32 }, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self { VehicleStatus::Parked | VehicleStatus::Driving { speed: _ } => true, _ => false, } } pub fn description(&self) -> String { // Your code here... match self { VehicleStatus::Parked => String::from("The vehicle is parked."), VehicleStatus::Driving { speed } => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}."), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving { speed: u32 }, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self { VehicleStatus::Parked | VehicleStatus::Driving { speed: _ } => true, _ => false, } } pub fn description(&self) -> String { // Your code here... match self { VehicleStatus::Parked => String::from("The vehicle is parked."), VehicleStatus::Driving { speed } => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}."), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub struct Parked;pub struct Driving { pub speed: u32,}pub struct BrokenDown(pub String);pub enum VehicleStatus { Parked, Driving { speed: u32 }, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { match self { Self::Driving { speed: _ } => return true, Self::Parked => return true, Self::BrokenDown(_) => return false, } } pub fn description(&self) -> String { match self { Self::Parked => "The vehicle is parked.".to_string(), Self::Driving { speed } => format!("The vehicle is driving at {speed} km/h."), Self::BrokenDown(reason) => format!("The vehicle is broken down: {reason}."), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { Parked, Driving { speed: u32 }, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { match self { VehicleStatus::Parked => true, VehicleStatus::Driving {speed: _} => true, VehicleStatus::BrokenDown(_reason) => false, } } pub fn description(&self) -> String { match self { VehicleStatus::Parked => format!("The vehicle is parked."), VehicleStatus::Driving {speed} => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}.") } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving {speed: u32}, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self { VehicleStatus::Parked => true, VehicleStatus::Driving{speed: _} => true, _ => false, } } pub fn description(&self) -> String { match self { VehicleStatus::Parked => "The vehicle is parked.".to_string(), VehicleStatus::Driving{speed: s} => format!("The vehicle is driving at {} km/h.", s), VehicleStatus::BrokenDown(r) => format!("The vehicle is broken down: {}.", r), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { Parked, Driving { speed: u32 }, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { !matches!(self, VehicleStatus::BrokenDown(_)) } pub fn description(&self) -> String { match self { VehicleStatus::Parked => "The vehicle is parked.".into(), VehicleStatus::Driving { speed } => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}."), } }}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving { speed: u32 }, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self { VehicleStatus::BrokenDown(_) => false, _ => true } } pub fn description(&self) -> String { // Your code here... match self { VehicleStatus::Parked => String::from("The vehicle is parked."), VehicleStatus::Driving{ speed } => format!("The vehicle is driving at {} km/h.", speed), VehicleStatus::BrokenDown(problem) => format!("The vehicle is broken down: {}.", problem), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked ,Driving {speed: u32 } ,BrokenDown(String)}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self{ VehicleStatus::BrokenDown(_) => return false, _ => return true } } pub fn description(&self) -> String { // Your code here... match self{ VehicleStatus::Parked => "The vehicle is parked.".to_string(), VehicleStatus::Driving {speed} => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}."), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked ,Driving { speed: u32 } ,BrokenDown(String)}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self{ VehicleStatus::BrokenDown(_) => return false, _ => return true } } pub fn description(&self) -> String { // Your code here... match self{ VehicleStatus::Parked => "The vehicle is parked.".to_string(), VehicleStatus::Driving { speed } => format!("The vehicle is driving at {} km/h.",speed), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}."), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving {speed: u32}, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match &self{ VehicleStatus::Parked | VehicleStatus::Driving{speed:_}=> true, VehicleStatus::BrokenDown(_) => false } } pub fn description(&self) -> String { // Your code here... match self{ VehicleStatus::Parked => "The vehicle is parked.".to_string(), VehicleStatus::Driving{speed} => format!("The vehicle is driving at {speed} km/h.").to_string(), VehicleStatus::BrokenDown(reason)=> format!("The vehicle is broken down: {reason}.").to_string() } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { Parked, Driving { speed: u32 }, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { match self { Self::Parked => true, Self::Driving { speed } => true, Self::BrokenDown(reason) => false, } } pub fn description(&self) -> String { match self { Self::Parked => "The vehicle is parked.".into(), Self::Driving { speed } => format!("The vehicle is driving at {speed} km/h."), Self::BrokenDown(reason) => format!("The vehicle is broken down: {reason}."), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { Parked, Driving { speed: u32, }, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { !matches!(self, VehicleStatus::BrokenDown(_)) } pub fn description(&self) -> String { match self { VehicleStatus::Parked => "The vehicle is parked.".to_string(), VehicleStatus::Driving { speed } => format!("The vehicle is driving at {} km/h.", speed), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {}.", reason), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { Parked, Driving { speed: u32, }, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { match self { VehicleStatus::BrokenDown(_) => false, _ => true, } } pub fn description(&self) -> String { match self { VehicleStatus::Parked => "The vehicle is parked.".to_string(), VehicleStatus::Driving { speed } => format!("The vehicle is driving at {} km/h.", speed), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {}.", reason), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving { speed: u32 }, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self { VehicleStatus::Parked | VehicleStatus::Driving { .. } => true, VehicleStatus::BrokenDown(_) => false, } } pub fn description(&self) -> String { // Your code here... match self { VehicleStatus::Parked => String::from("The vehicle is parked."), VehicleStatus::Driving { speed } => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}."), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving { speed: u32 }, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self { VehicleStatus::Parked | VehicleStatus::Driving { speed: _ } => true, VehicleStatus::BrokenDown(_) => false, } } pub fn description(&self) -> String { // Your code here... match self { VehicleStatus::Parked => String::from("The vehicle is parked."), VehicleStatus::Driving { speed } => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}."), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { Parked, Driving {speed: u32}, BrokenDown(String)}impl VehicleStatus { pub fn is_operational(&self) -> bool { matches!(self, VehicleStatus::Parked | VehicleStatus::Driving { .. }) } pub fn description(&self) -> String { match self { VehicleStatus::Parked => "The vehicle is parked.".to_string(), VehicleStatus::Driving { speed } => format!("The vehicle is driving at {} km/h.", speed), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {}.", reason) } }} // Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving {speed: u32}, BrokenDown(String)}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self { VehicleStatus::Parked | VehicleStatus::Driving{..} => true, VehicleStatus::BrokenDown(_) => false, } } pub fn description(&self) -> String { match self { VehicleStatus::Parked => "The vehicle is parked.".to_owned(), VehicleStatus::Driving{speed} => format!("The vehicle is driving at {} km/h.",speed), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {}.", reason) } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving { speed : u32 }, BrokenDown (String)}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match &self { VehicleStatus::Parked => true, VehicleStatus::Driving {speed} => true, _ => false } } pub fn description(&self) -> String { // Your code here... match &self { VehicleStatus::Parked => format!("The vehicle is parked."), VehicleStatus::Driving { speed } => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}."), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving {speed: i32}, BrokenDown(String),}use VehicleStatus::{Parked, Driving, BrokenDown};impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... if let BrokenDown(_) = self { false } else { true } } pub fn description(&self) -> String { // Your code here... match self { Parked => "The vehicle is parked.".to_string(), Driving {speed} => format!("The vehicle is driving at {speed} km/h."), BrokenDown(reason) => format!("The vehicle is broken down: {reason}.") } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving {speed : u32}, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self{ VehicleStatus::Parked=>true, VehicleStatus::Driving{speed}=>true, VehicleStatus::BrokenDown(_)=>false, } } pub fn description(&self) -> String { // Your code here... match self{ VehicleStatus::Parked=>String::from("The vehicle is parked."), VehicleStatus::Driving{speed} => String::from(format!("The vehicle is driving at {} km/h.",speed)), VehicleStatus::BrokenDown(reason) => String::from(format!("The vehicle is broken down: {}.",reason)), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving {speed: u32}, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self { VehicleStatus::BrokenDown(_) => false, _ => true } } pub fn description(&self) -> String { // Your code here... match self { VehicleStatus::Parked => String::from("The vehicle is parked."), VehicleStatus::Driving{speed} => format!("The vehicle is driving at {speed} km/h.").to_string(), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}.").to_string() } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { Parked, Driving {speed: u32}, BrokenDown(String) // Define the VehicleStatus variants here}impl VehicleStatus { pub fn is_operational(&self) -> bool { match self { VehicleStatus::BrokenDown(_) => false, _ => true } // Your code here... } pub fn description(&self) -> String { match self { VehicleStatus::Parked => String::from("The vehicle is parked."), VehicleStatus::Driving{speed} => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}.") } // Your code here... }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving{speed: u32}, BrokenDown(String)}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self { VehicleStatus::Parked => true, VehicleStatus::Driving{speed} => true, VehicleStatus::BrokenDown(reason)=>false } } pub fn description(&self) -> String { // Your code here... match self { VehicleStatus::Parked => "The vehicle is parked.".to_string(), VehicleStatus::Driving{speed} => format!("The vehicle is driving at {speed} km/h.").to_string(), VehicleStatus::BrokenDown(reason)=>format!("The vehicle is broken down: {reason}.").to_string() } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving{speed:u32}, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self{ VehicleStatus::BrokenDown(_) => return false, _ => return true, } } pub fn description(&self) -> String { // Your code here... match self{ VehicleStatus::Parked => String::from("The vehicle is parked."), VehicleStatus::Driving{speed} => format!("The vehicle is driving at {} km/h.",speed), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {}.", reason), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving {speed: u32}, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { match self { VehicleStatus::BrokenDown(_) => false, _ => true, } } pub fn description(&self) -> String { match self { VehicleStatus::Parked => "The vehicle is parked.".to_string(), VehicleStatus::Driving{speed} => format!("The vehicle is driving at {} km/h.", speed), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {}.", reason), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving{speed: u32}, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { match &self { VehicleStatus::Parked | VehicleStatus::Driving{..} => true, VehicleStatus::BrokenDown(_) => false, } } pub fn description(&self) -> String { match &self { VehicleStatus::Parked => "The vehicle is parked.".to_string(), VehicleStatus::Driving{speed} => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}."), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving { speed: u32 }, BrokenDown(String)}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self { Self::BrokenDown(_) => false, _ => true } } pub fn description(&self) -> String { // Your code here... match self { Self::Parked => "The vehicle is parked.".to_string(), Self::Driving { speed } => format!("The vehicle is driving at {speed} km/h."), Self::BrokenDown(reason) => format!("The vehicle is broken down: {reason}.") } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { Parked, Driving { speed: u32 }, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { match self { VehicleStatus::BrokenDown(_) => false, _ => true, } } pub fn description(&self) -> String { match self { VehicleStatus::Parked => String::from("The vehicle is parked."), VehicleStatus::Driving { speed } => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}."), } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving{speed:u32}, BrokenDown(String)}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self{ VehicleStatus::BrokenDown(_) => false, _ => true, } } pub fn description(&self) -> String { // Your code here... return match self{ VehicleStatus::Parked => format!("The vehicle is parked."), VehicleStatus::Driving{speed} => format!("The vehicle is driving at {} km/h.", speed), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {}.", reason) } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving { speed: u32}, BrokenDown(String),}impl VehicleStatus { pub fn is_operational(&self) -> bool { if let VehicleStatus::BrokenDown(_) = self { false } else { true } } pub fn description(&self) -> String { match self { VehicleStatus::Parked => String::from("The vehicle is parked."), VehicleStatus::Driving{speed} => { format!("The vehicle is driving at {speed} km/h.") }, VehicleStatus::BrokenDown(reason) => { format!("The vehicle is broken down: {reason}.") }, } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}pub enum VehicleStatus { // Define the VehicleStatus variants here Parked, Driving{speed: u32}, BrokenDown(String)}impl VehicleStatus { pub fn is_operational(&self) -> bool { // Your code here... match self { VehicleStatus::Parked => true, VehicleStatus::Driving{..} => true, VehicleStatus::BrokenDown(_) => false } } pub fn description(&self) -> String { // Your code here... match self { VehicleStatus::Parked => "The vehicle is parked.".to_string(), VehicleStatus::Driving{speed} => format!("The vehicle is driving at {speed} km/h."), VehicleStatus::BrokenDown(reason) => format!("The vehicle is broken down: {reason}.") } }}// Example use casepub fn main() { let parked = VehicleStatus::Parked; assert!(parked.is_operational()); assert_eq!(parked.description(), "The vehicle is parked."); let driving = VehicleStatus::Driving { speed: 80 }; assert!(driving.is_operational()); assert_eq!(driving.description(), "The vehicle is driving at 80 km/h."); let broken_down = VehicleStatus::BrokenDown("Flat tire".to_string()); assert!(!broken_down.is_operational()); assert_eq!( broken_down.description(), "The vehicle is broken down: Flat tire." );}