]>
git.proxmox.com Git - rustc.git/blob - vendor/itertools-0.8.2/src/exactly_one_err.rs
1 use std
::iter
::ExactSizeIterator
;
5 /// Iterator returned for the error case of `IterTools::exactly_one()`
6 /// This iterator yields exactly the same elements as the input iterator.
8 /// During the execution of exactly_one the iterator must be mutated. This wrapper
9 /// effectively "restores" the state of the input iterator when it's handed back.
11 /// This is very similar to PutBackN except this iterator only supports 0-2 elements and does not
13 #[derive(Debug, Clone)]
14 pub struct ExactlyOneError
<I
>
18 first_two
: (Option
<I
::Item
>, Option
<I
::Item
>),
22 impl<I
> ExactlyOneError
<I
>
26 /// Creates a new `ExactlyOneErr` iterator.
27 pub(crate) fn new(first_two
: (Option
<I
::Item
>, Option
<I
::Item
>), inner
: I
) -> Self {
28 Self { first_two, inner }
32 impl<I
> Iterator
for ExactlyOneError
<I
>
38 fn next(&mut self) -> Option
<Self::Item
> {
42 .or_else(|| self.first_two
.1.take())
43 .or_else(|| self.inner
.next())
46 fn size_hint(&self) -> (usize, Option
<usize>) {
47 let mut additional_len
= 0;
48 if self.first_two
.0.is_some
() {
51 if self.first_two
.1.is_some
() {
54 size_hint
::add_scalar(self.inner
.size_hint(), additional_len
)
58 impl<I
> ExactSizeIterator
for ExactlyOneError
<I
> where I
: ExactSizeIterator {}