sysfuss 0.3.0

sysfs wrapper for convenience
Documentation
/// Multi-error convenience enum
#[derive(Debug, Clone)]
pub enum EitherErr2<T1, T2> {
    /// Type 1
    First(T1),
    /// Type 2
    Second(T2),
}

impl <T1, T2> EitherErr2<T1, T2> {
    /// Is this the first error type?
    pub fn is_type1(&self) -> bool {
        matches!(self, Self::First(_))
    }
    
    /// Is this the second error type?
    pub fn is_type2(&self) -> bool {
        matches!(self, Self::Second(_))
    }
}

impl <T> EitherErr2<std::convert::Infallible, T> {
    /// Convert to non-infallible error
    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> {
    /// Convert to non-infallible error
    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> {}

/// Value parse error for an enumeration.
/// This usually indicates an unexpected value (one without an enum variant) was received while parsing.
#[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> {}