I can't figure out how to take two BTreeSet objects and create a new, owned, BTreeSet from the intersection operation.
Here is a Minimal Example:
use std::collections::BTreeSet;
fn test() -> BTreeSet<u64> {
let mut s1 = BTreeSet::new();
let mut s2 = BTreeSet::new();
s1.insert(1u64);
s2.insert(2u64);
let s_out = s1.intersection(&s2);
return s_out; // this does not work
}
The reason this does not work appears to be because intersection
creates an iterator, which is lazy evaluated. I want to create a new "owned" object / BTreeSet from the existing two BTreeSets.
How do I do that?
intersection
returns some other kind of object which is an Intersection
object. The intended purpose is presumably so that it can be lazy-evaluated. (See docs.)