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