The source code to demonstrate the match statement with enum is given below. The given program is compiled and executed successfully.
// Rust program to demonstrate the
// match statement with enum
enum Country {
INDIA,
USA,
UK,
CANADA,
}
fn main() {
let country=Country::INDIA;
match country {
Country::INDIA=> println!("Welcome to INDIA"),
Country::UK=> println!("Welcome to UK"),
Country::USA=> println!("Welcome to USA"),
Country::CANADA=> println!("Welcome to CANADA"),
_=> println!("Invalid country")
};
}
Output:
Welcome to INDIA
Explanation:
Here, we created an enum country. Then we matched the enum of countries using the match statement and printed the appropriate message.
Program/Source Code:
The source code to demonstrate the match statement with enum is given below. The given program is compiled and executed successfully.
Output:
Explanation:
Here, we created an enum country. Then we matched the enum of countries using the match statement and printed the appropriate message.
need an explanation for this answer? contact us directly to get an explanation for this answer