Last active
August 29, 2015 14:03
-
-
Save yorkie/e8babab7e8e5d135709d to your computer and use it in GitHub Desktop.
why use a not age?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// an example shows how rust make @ in match expression systax | |
match age { | |
a @ 0..20 => println!("{} years old", age), | |
_ => println!("older than 21") | |
} | |
// That's because we can | |
fn inc_age(mut age: int) -> int { | |
age + 1 | |
} | |
fn main() { | |
let mut age = 10; | |
match inc_age(age) { | |
// we don't use `let a = inc_age(age)`, so convenient ! | |
a @ 0..20 => println!("{} years old", a), | |
_ => println!("old than 21") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment