Skip to content

Instantly share code, notes, and snippets.

@yorkie
Last active August 29, 2015 14:03
Show Gist options
  • Save yorkie/e8babab7e8e5d135709d to your computer and use it in GitHub Desktop.
Save yorkie/e8babab7e8e5d135709d to your computer and use it in GitHub Desktop.
why use a not age?
// 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