Created
April 8, 2022 18:53
-
-
Save jcar787/d0b3a6d147852061154c91bd1a7eb818 to your computer and use it in GitHub Desktop.
Match with Enum example in rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum StagesInLife { | |
Birth(String), | |
Grow, | |
Work(String), | |
Retirement { age: u8, pension: f32 } | |
} | |
fn main() { | |
let work = StagesInLife::Work("Principal Software Engineer".to_string()); | |
match work { | |
StagesInLife::Birth(name) => println!("Your name is: {}", name), | |
StagesInLife::Grow => println!("Cool, you're getting older"), | |
StagesInLife::Work(title) => println!("Your job is: {}", title), | |
StagesInLife::Retirement{age, pension} => println!("Your age is: {} and your pension is {}", age, pension), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment