i2c_multiplexer/
error.rs

1use embedded_hal::i2c::{Error, ErrorKind};
2use thiserror::Error;
3
4pub type Result<T, I2cError> = core::result::Result<T, MultiplexerError<I2cError>>;
5
6#[derive(Error, Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq)]
7pub enum MultiplexerError<I2cError>
8where
9    I2cError: Error,
10{
11    #[error("Write Read I2C Error")]
12    WriteReadI2CError,
13    #[error("Write I2C Error")]
14    WriteI2CError,
15    #[error("Read I2C Error")]
16    ReadI2CError,
17    #[error("Incorrect port supplied")]
18    PortError,
19    #[error("I2C Error")]
20    I2CError(I2cError),
21}
22
23impl<I2cError> Error for MultiplexerError<I2cError>
24where
25    I2cError: Error,
26{
27    fn kind(&self) -> ErrorKind {
28        match self {
29            Self::I2CError(e) => e.kind(),
30            _ => ErrorKind::Other,
31        }
32    }
33}