midenc_hir/itertools.rs
1pub trait IteratorExt {
2 /// Returns true if the given iterator consists of exactly one element
3 fn has_single_element(&mut self) -> bool;
4}
5
6impl<I: Iterator> IteratorExt for I {
7 default fn has_single_element(&mut self) -> bool {
8 self.next().is_some_and(|_| self.next().is_none())
9 }
10}
11
12impl<I: ExactSizeIterator> IteratorExt for I {
13 #[inline]
14 fn has_single_element(&mut self) -> bool {
15 self.len() == 1
16 }
17}