std-method

BTreeSet::symmetric_difference

Traverse items in exactly one of the two sets. Shared items are omitted. Expected stdout (not executed): [1, 3] Common mistake: Assuming the result identifies which items were added and which were removed.

Formal Syntax & Structure

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

Working Example

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