rust - Rust if let Optionals 和比较条件
问题描述
我有很多这样的代码,为了清楚起见,我想用"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 {
...
}
解决方案
推荐阅读
- sql - json pgsql 类型的输入语法无效
- sql - 如何在 MariaDB 中存储 RETURNING * 的结果?
- python - 从 s3 存储桶读取 .txt 文件不返回所有文件内容
- python - 计算具有相同键索引的值之间的差异
- angular - Mat-pagination 不会在添加行后将我引导到新页面
- laravel - Laravel 使用克隆的模型数据填充表单
- excel - 通过 VBA 从不同的工作簿进行 XLookup
- integration - Mulesoftt 社区版。停产了吗?
- javascript - React 组件不会重新渲染
- visual-studio-code - 如何让 VSCode 自动打开内联差异中的所有文件?