首页 > 解决方案 > 惯用的取消引用映射键

问题描述

我想从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();

我想让HashSets 使用intersection().

代码运行,但我的问题是:

标签: rust

解决方案


推荐阅读