std-method

BTreeSet::intersection

Traverse items present in both sets. No new owned set is created until collection is requested. Expected stdout (not executed): [2, 5] Common mistake: Including items that appear in only one set.

Formal Syntax & Structure

rust syntaxrust
fn intersection<'a>(&'a self, other: &'a BTreeSet<T>) -> Intersection<'a, T>

Working Example

Example Snippetrust
fn main() {    use std::collections::BTreeSet;    let weekday = BTreeSet::from([1, 2, 3, 4, 5]);    let available = BTreeSet::from([2, 5, 7]);    println!("{:?}", weekday.intersection(&available).copied().collect::<Vec<_>>());}
Rust Reference