use std::{error::Error as StdError, fmt};
#[derive(Debug)]
pub enum Error {
Any(Box<dyn StdError + Send + Sync + 'static>),
UnknownDevice,
UnableToStartBus,
PoisonedBusMutex,
}
impl<'a> fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::UnknownDevice => write!(f, "Unable to identify MATRIX device."),
Error::UnableToStartBus => write!(f, "Could not start the MATRIX bus."),
Error::PoisonedBusMutex => write!(f, "Mutex for MATRIX bus is unreachable."),
_ => write!(f, "TODO: ADD ERROR DESCRIPTION!"),
}
}
}
use nix;
impl From<nix::Error> for Error {
fn from(error: nix::Error) -> Self {
Error::UnableToStartBus
}
}
use std::sync::MutexGuard;
use std::sync::PoisonError;
impl From<PoisonError<MutexGuard<'_, ()>>> for Error {
fn from(_: PoisonError<MutexGuard<()>>) -> Self {
Error::PoisonedBusMutex
}
}