resolve: Avoid some unstable iteration

This commit is contained in:
Vadim Petrochenkov 2025-03-14 17:18:41 +03:00
parent f7b4354283
commit a891139df1
9 changed files with 51 additions and 41 deletions

View file

@ -259,6 +259,12 @@ impl<V: Eq + Hash> UnordSet<V> {
self.inner.is_empty()
}
/// If the set has only one element, returns it, otherwise returns `None`.
#[inline]
pub fn get_only(&self) -> Option<&V> {
if self.inner.len() == 1 { self.inner.iter().next() } else { None }
}
#[inline]
pub fn insert(&mut self, v: V) -> bool {
self.inner.insert(v)