#[derive(Debug, Clone)]
pub enum EitherErr2<T1, T2> {
First(T1),
Second(T2),
}
impl <T1, T2> EitherErr2<T1, T2> {
pub fn is_type1(&self) -> bool {
matches!(self, Self::First(_))
}
pub fn is_type2(&self) -> bool {
matches!(self, Self::Second(_))
}
}
impl <T> EitherErr2<std::convert::Infallible, T> {
pub fn map_infallible_first(self) -> T {
match self {
Self::First(_e) => panic!("Infallible error cannot exist"),
Self::Second(e) => e,
}
}
}
impl <T> EitherErr2<T, std::convert::Infallible> {
pub fn map_infallible_second(self) -> T {
match self {
Self::First(e) => e,
Self::Second(_e) => panic!("Infallible error cannot exist"),
}
}
}
impl <T1: std::fmt::Display, T2: std::fmt::Display> std::fmt::Display for EitherErr2<T1, T2> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::First(x) => write!(f, "{}", x),
Self::Second(x) => write!(f, "{}", x),
}
}
}
impl <T1: std::error::Error, T2: std::error::Error> std::error::Error for EitherErr2<T1, T2> {}
#[derive(Debug, Clone)]
pub struct ValueEnumError<'a> {
pub(crate) got: String,
pub(crate) allowed: &'a [&'a str],
}
impl <'a> std::fmt::Display for ValueEnumError<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Got {}, expected one of {:?}", self.got, self.allowed)
}
}
impl <'a> std::error::Error for ValueEnumError<'a> {}