例子:
// 4、通过..匹配
fn main() {
// let x = 5;
// match x {
// 1..=5 => println!("1 to 5"), // 1|2|3|4|5 => println!("1 to 5"),
// _ => println!("xx"),
// };
let x = 'c';
match x {
'a'..='j' => println!("1"),
'k'..='z' => println!("2"),
_ => println!("other"),
}
}
本节全部源代码:
https://github.com/anonymousGiga/learn_rust/blob/master/learn_pattern2/src/main.rs