Skip to content

Commit 63b04e5

Browse files
committed
AllEqualValueError implements std::error::Error
1 parent 3e1b7ea commit 63b04e5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/all_equal_value_err.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
#[cfg(feature = "use_std")]
2+
use std::error::Error;
3+
use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
4+
15
/// Value returned for the error case of `Itertools::all_equal_value()`.
26
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
37
pub struct AllEqualValueError<Item>(pub Option<[Item; 2]>);
8+
9+
impl<Item> Display for AllEqualValueError<Item> {
10+
fn fmt(&self, f: &mut Formatter) -> FmtResult {
11+
match self.0 {
12+
None => {
13+
write!(
14+
f,
15+
"got zero elements when all elements were expected to be equal"
16+
)
17+
}
18+
Some([_, _]) => {
19+
write!(
20+
f,
21+
"got different elements when all elements were expected to be equal"
22+
)
23+
}
24+
}
25+
}
26+
}
27+
28+
#[cfg(feature = "use_std")]
29+
impl<Item> Error for AllEqualValueError<Item> where Item: Debug {}

0 commit comments

Comments
 (0)