我有很多这样的代码,并且想要用"if let"
绑定来替换,以增加我的代码可读性。
// contrived
fn maybe() -> Option<i32> { Some(1)}
let maybe_num_A = maybe();
let maybe_num_B = maybe();
...
match (maybe_num_A, maybe_num_B) {
(Some(a) , Some(b)) if a > b => {
....
}
_ => {} // don't care many times about the other matches that doesn't hold. how to get rid of this?
}
不确定如何使用语法将 let 与比较绑定:
if let (Some(a),Some(b) = (maybe_num_A, maybe_num_B) ???&&??? a > b {
...
}