Flow control match binding in RBE
This commit is contained in:
parent
ca812add16
commit
6e50ec65f8
14
rustbyexample/flow_control.d/match.d/binding.rs
Normal file
14
rustbyexample/flow_control.d/match.d/binding.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
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),
|
||||||
|
}
|
||||||
|
}
|
11
rustbyexample/flow_control.d/match.d/binding2.rs
Normal file
11
rustbyexample/flow_control.d/match.d/binding2.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fn some_number() -> Option<u32> {
|
||||||
|
Some(42)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
match some_number() {
|
||||||
|
Some(n @ 42) => println!("The Answer: {}!", n),
|
||||||
|
Some(n) => println!("Not interesting... {}", n),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user