Skip to content

Instantly share code, notes, and snippets.

@jcar787
Created April 8, 2022 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcar787/d0b3a6d147852061154c91bd1a7eb818 to your computer and use it in GitHub Desktop.
Save jcar787/d0b3a6d147852061154c91bd1a7eb818 to your computer and use it in GitHub Desktop.
Match with Enum example in rust
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