I was trying to work around some limitations of BTreeSet and the Ord trait. Basically,
-
Ord only allows comparing T to T.
-
BTreeSet::<T>::range allows querying by any type Q such that T: Borrow<Q>, Q: Ord (i.e., Q can be borrowed from T and Q implements Ord).
Given BTreeSet<(A, B, C)> I wanted to query for all (a, b, *). Ord can’t be used to compare (A, B) to (A, B, C) (not the same type) so I needed to be able to “borrow” my query type from (A, B, C).
However, the better way to do this would be to change the range method to take a some type implementing a RangeQuery trait:
trait RangeQuery<T> {
fn cmp(&self, &T) -> Ordering;
}
(like Ord but T doesn’t have to be Self).