Skip to content

Instantly share code, notes, and snippets.

@Shaun289
Created October 22, 2021 22:24
Show Gist options
  • Save Shaun289/871f2c5399bf00eca5c5c44d265a5fa5 to your computer and use it in GitHub Desktop.
Save Shaun289/871f2c5399bf00eca5c5c44d265a5fa5 to your computer and use it in GitHub Desktop.
rust study : match
/*
The rust by example ko https://hanbum.gitbooks.io/rustbyexample/content/flow_control/match.html
compiled on https://play.rust-lang.org/
Notice : exclusive range patterns https://github.com/rust-lang/rust/issues/37854
*/
fn main()
{
for number in 1..22 {
println!("Tell me about {}", number);
match number {
1 => println!("One!"),
2 | 3 | 5 | 7 | 11 => println!("{} is a prime.", number),
13..=20 => println!("A teen"),
_ => println!("Ain't special")
}
}
let b = true;
let binary = match b {
false => 0,
true => 1,
};
println!("{} -> {}", b, binary);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment