Much more flow control destructuring in RBE
This commit is contained in:
16
rustbyexample/flow_control.d/match.d/guard.rs
Normal file
16
rustbyexample/flow_control.d/match.d/guard.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
#[allow(dead_code)]
|
||||
enum Temperature {
|
||||
Celsius(i32),
|
||||
Fahrenheit(i32),
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let temperature = Temperature::Celsius(35);
|
||||
|
||||
match temperature {
|
||||
Temperature::Celsius(t) if t > 30 => println!("{}C is above 30 Celsius", t),
|
||||
Temperature::Celsius(t) => println!("{}C is below 30 Celsius", t),
|
||||
Temperature::Fahrenheit(t) if t > 86 => println!("{}F is above 86 Fahrenheit", t),
|
||||
Temperature::Fahrenheit(t) => println!("{}F is below 86 Fahrenheit", t),
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user