Advertisement
cwchen

[Rust] match as an expression

Aug 22nd, 2017
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.26 KB | None | 0 0
  1. fn main() {
  2.     let char = 'c';
  3.  
  4.     let sound = match char {
  5.         'A' | 'a' | 'E' | 'e' | 'I' | 'i' | 'O' | 'o' | 'U' |'u' => "vowel",
  6.         'A' ... 'Z' | 'a' ... 'z' => "consonant",
  7.         _ => "other"
  8.     };
  9.  
  10.     assert_eq!(sound, "consonant");
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement