Avoid a reverse map that is only used in diagnostics paths
This commit is contained in:
parent
18a029cfe8
commit
24efefafcb
8 changed files with 32 additions and 17 deletions
|
@ -109,6 +109,16 @@ impl<T, I: Iterator<Item = T>> UnordItems<T, I> {
|
|||
pub fn collect<C: From<UnordItems<T, I>>>(self) -> C {
|
||||
self.into()
|
||||
}
|
||||
|
||||
/// If the iterator has only one element, returns it, otherwise returns `None`.
|
||||
#[track_caller]
|
||||
pub fn get_only(mut self) -> Option<T> {
|
||||
let item = self.0.next();
|
||||
if self.0.next().is_some() {
|
||||
return None;
|
||||
}
|
||||
item
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> UnordItems<T, std::iter::Empty<T>> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue