winget_types/traits/closest.rs
1pub trait Closest {
2 fn closest<'iter, I, T>(&self, candidates: I) -> Option<&'iter Self>
3 where
4 I: IntoIterator<Item = T>,
5 T: Into<&'iter Self>,
6 {
7 candidates
8 .into_iter()
9 .map(T::into)
10 .min_by_key(|candidate| self.distance_key(candidate))
11 }
12
13 fn distance_key(&self, other: &Self) -> impl Ord;
14}