1#[derive(Debug, Clone)]
3pub enum EitherErr2<T1, T2> {
4 First(T1),
6 Second(T2),
8}
9
10impl <T1, T2> EitherErr2<T1, T2> {
11 pub fn is_type1(&self) -> bool {
13 matches!(self, Self::First(_))
14 }
15
16 pub fn is_type2(&self) -> bool {
18 matches!(self, Self::Second(_))
19 }
20}
21
22impl <T> EitherErr2<std::convert::Infallible, T> {
23 pub fn map_infallible_first(self) -> T {
25 match self {
26 Self::First(_e) => panic!("Infallible error cannot exist"),
27 Self::Second(e) => e,
28 }
29 }
30}
31
32impl <T> EitherErr2<T, std::convert::Infallible> {
33 pub fn map_infallible_second(self) -> T {
35 match self {
36 Self::First(e) => e,
37 Self::Second(_e) => panic!("Infallible error cannot exist"),
38 }
39 }
40}
41
42impl <T1: std::fmt::Display, T2: std::fmt::Display> std::fmt::Display for EitherErr2<T1, T2> {
43 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44 match self {
45 Self::First(x) => write!(f, "{}", x),
46 Self::Second(x) => write!(f, "{}", x),
47 }
48 }
49}
50
51impl <T1: std::error::Error, T2: std::error::Error> std::error::Error for EitherErr2<T1, T2> {}
52
53#[derive(Debug, Clone)]
56pub struct ValueEnumError<'a> {
57 pub(crate) got: String,
58 pub(crate) allowed: &'a [&'a str],
59}
60
61impl <'a> std::fmt::Display for ValueEnumError<'a> {
62 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
63 write!(f, "Got {}, expected one of {:?}", self.got, self.allowed)
64 }
65}
66
67impl <'a> std::error::Error for ValueEnumError<'a> {}