std-method
BTreeSet::difference
Traverse items in the receiver but not in the argument. Direction matters: reversing the sets can change the answer. Expected stdout (not executed): ["A", "C"] Common mistake: Treating difference as symmetric.
Formal Syntax & Structure
rust syntaxrust
fn difference<'a>(&'a self, other: &'a BTreeSet<T>) -> Difference<'a, T>Working Example
Example Snippetrust
fn main() { use std::collections::BTreeSet; let required = BTreeSet::from(["A", "B", "C"]); let done = BTreeSet::from(["B", "D"]); println!("{:?}", required.difference(&done).copied().collect::<Vec<_>>());}