Instead of common elements, sometimes the opposite is required—removing elements that occur in both sets. This operation is also referred to as the complement of two sets, which only inserts elements into the result if they don't occur in the other set:
pub fn difference(self, other: TrieSet<K>) -> TrieSet<K> {
let new = RefCell::new(TrieSet::new_empty());
self.walk(|k| {
if !other.contains(k) {
new.borrow_mut().insert(k)
}
});
new.into_inner()
}
With that, the set is finished, and all the desired functionality can be provided.