box-o-sand/rustbyexample/flow_control.d/match.d/binding.rs

15 lines
372 B
Rust
Raw Normal View History

2023-09-29 20:52:18 +00:00
fn age() -> u32 {
15
}
fn main() {
println!("Tell me what type of person you are");
match age() {
0 => println!("I haven't celebrated my first birthday yet"),
n @ 1..=12 => println!("I'm a child of age {:?}", n),
n @ 13..=19 => println!("I'm a teen of age {:?}", n),
n => println!("I'm an old person of age {:?}", n),
}
}