rust - 惯用的取消引用映射键
问题描述
我想从RustHashSet
中两个 s 的键中取出两个s。HashMap
我的代码如下所示:
let mut wire1_map: HashMap<(i32, i32), u32> = HashMap::new();
get_route(&mut wire1_map, &wire1);
let mut wire2_map: HashMap<(i32, i32), u32> = HashMap::new();
get_route(&mut wire2_map, &wire2);
let wire1_set: HashSet<(i32, i32)> = wire1_map.keys().map(|x| *x).collect();
let wire2_set: HashSet<(i32, i32)> = wire2_map.keys().map(|x| *x).collect();
let is = wire1_set.intersection(&wire2_set);
let m_dist = is.map(|ele| calc_distance((0, 0), *ele)).min().unwrap();
我想让HashSet
s 使用intersection()
.
代码运行,但我的问题是:
- 一般来说,这是惯用的 Rust 代码吗?
- 是否有更简单(更惯用)的方法来取消引用地图的每个键?
解决方案
推荐阅读
- java - 重写代码只得到几个变量
- jquery - jQuery:按两个参数对列表进行排序
- maven - Maven Surefire:启动分叉时发生错误
- r - 为各种 stat_ellipse 添加图例
- tableau-api - 在 Tableau 中连接到 SQL Analysis Services 时在图表后面显示完整数据集
- amazon-web-services - 如何授予对特定存储桶的访问权限?
- python - 如何修复错误异常以允许重试而不在 Python 中循环异常
- c# - 从以 varbinary 格式保存的 SQL 读取数据并在系统发送的电子邮件中附加文件?
- javascript - 如何使用反应测试库测试自定义 Hook
- excel - 保存自动过滤器设置并重新应用