September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
31
Task/Extend-your-language/Rust/extend-your-language.rust
Normal file
31
Task/Extend-your-language/Rust/extend-your-language.rust
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#![allow(unused_variables)]
|
||||
macro_rules! if2 {
|
||||
($cond1: expr, $cond2: expr
|
||||
=> $both:expr
|
||||
=> $first: expr
|
||||
=> $second:expr
|
||||
=> $none:expr)
|
||||
=> {
|
||||
match ($cond1, $cond2) {
|
||||
(true, true) => $both,
|
||||
(true, _ ) => $first,
|
||||
(_ , true) => $second,
|
||||
_ => $none
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let i = 1;
|
||||
let j = 2;
|
||||
if2!(i > j, i + j >= 3
|
||||
=> {
|
||||
// code blocks and statements can go here also
|
||||
let k = i + j;
|
||||
println!("both were true")
|
||||
}
|
||||
=> println!("the first was true")
|
||||
=> println!("the second was true")
|
||||
=> println!("neither were true")
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue