如何在match
语句中获取通配符臂的值?
例如:
let a = 1i;
let b = 2i;
match a.cmp(&b) {
Greater => println!("is greater"),
_ => println!("is {}", _) // error: unexpected token: `_`
}
我希望能比在变量中存储匹配的enum
更清晰:
let a = 1i;
let b = 2i;
let ord = a.cmp(&b);
match ord {
Greater => println!("is greater"),
_ => println!("is {}", ord)
}
答案 0 :(得分:1)
这是你要求的吗?
let a = 1i;
let b = 2i;
match a.cmp(&b) {
Greater => println!("is greater"),
e => println!("is {}", e)
}