Skip to content

Commit 50d01b4

Browse files
stepanchegphimuemue
authored andcommitted
Specialize ExactlyOneError::count
1 parent 041c733 commit 50d01b4

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/exactly_one_err.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ where
6464
size_hint::add_scalar(self.inner.size_hint(), self.additional_len())
6565
}
6666

67+
fn count(self) -> usize
68+
where
69+
Self: Sized,
70+
{
71+
self.additional_len() + self.inner.count()
72+
}
73+
6774
fn fold<B, F>(self, mut init: B, mut f: F) -> B
6875
where
6976
F: FnMut(B, Self::Item) -> B,

tests/quick.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,16 @@ quickcheck! {
13901390
}
13911391
}
13921392

1393+
quickcheck! {
1394+
fn exactly_one_count(a: Vec<i32>) -> TestResult {
1395+
let ret = a.iter().cloned().exactly_one();
1396+
match a.len() {
1397+
1 => TestResult::passed(),
1398+
len => TestResult::from_bool(len == ret.unwrap_err().count()),
1399+
}
1400+
}
1401+
}
1402+
13931403
quickcheck! {
13941404
fn at_most_one_i32(a: Vec<i32>) -> TestResult {
13951405
let ret = a.iter().cloned().at_most_one();

0 commit comments

Comments
 (0)