diff --git a/src/exactly_one_err.rs b/src/exactly_one_err.rs index e24d33fc5..47c734c1a 100644 --- a/src/exactly_one_err.rs +++ b/src/exactly_one_err.rs @@ -63,6 +63,21 @@ where fn size_hint(&self) -> (usize, Option) { size_hint::add_scalar(self.inner.size_hint(), self.additional_len()) } + + fn fold(self, mut init: B, mut f: F) -> B + where + F: FnMut(B, Self::Item) -> B, + { + match self.first_two { + Some(Either::Left([first, second])) => { + init = f(init, first); + init = f(init, second); + } + Some(Either::Right(second)) => init = f(init, second), + None => {} + } + self.inner.fold(init, f) + } } impl ExactSizeIterator for ExactlyOneError where I: ExactSizeIterator {} diff --git a/tests/specializations.rs b/tests/specializations.rs index abe41fe92..e14b1b669 100644 --- a/tests/specializations.rs +++ b/tests/specializations.rs @@ -330,6 +330,17 @@ quickcheck! { test_specializations(&it); test_double_ended_specializations(&it); } + + fn exactly_one_error(v: Vec) -> TestResult { + // Use `at_most_one` would be similar. + match v.iter().exactly_one() { + Ok(_) => TestResult::discard(), + Err(it) => { + test_specializations(&it); + TestResult::passed() + } + } + } } quickcheck! {