Skip to content

Commit 5f3cb52

Browse files
Philippe-Choletphimuemue
authored andcommitted
ExactlyOneError::fold
1 parent 298eb8b commit 5f3cb52

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/exactly_one_err.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ where
6363
fn size_hint(&self) -> (usize, Option<usize>) {
6464
size_hint::add_scalar(self.inner.size_hint(), self.additional_len())
6565
}
66+
67+
fn fold<B, F>(self, mut init: B, mut f: F) -> B
68+
where
69+
F: FnMut(B, Self::Item) -> B,
70+
{
71+
match self.first_two {
72+
Some(Either::Left([first, second])) => {
73+
init = f(init, first);
74+
init = f(init, second);
75+
}
76+
Some(Either::Right(second)) => init = f(init, second),
77+
None => {}
78+
}
79+
self.inner.fold(init, f)
80+
}
6681
}
6782

6883
impl<I> ExactSizeIterator for ExactlyOneError<I> where I: ExactSizeIterator {}

0 commit comments

Comments
 (0)