当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Rust HashSet.intersection用法及代码示例


本文简要介绍rust语言中 std::collections::hash_set::HashSet.intersection 的用法。

用法

pub fn intersection<'a>(    &'a self,     other: &'a HashSet<T, S>) -> Intersection<'a, T, S>

访问表示交叉点的值,即 selfother 中的值。

例子

use std::collections::HashSet;
let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();

// Print 2, 3 in arbitrary order.
for x in a.intersection(&b) {
    println!("{}", x);
}

let intersection: HashSet<_> = a.intersection(&b).collect();
assert_eq!(intersection, [2, 3].iter().collect());

相关用法


注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 std::collections::hash_set::HashSet.intersection。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。