use embedded_hal::i2c::ErrorKind;
use std::error::Error;
use std::fmt::{Debug, Display, Formatter};

#[derive(Copy, Clone, Debug)]
pub struct WrappingError<ERR: Debug>(pub ERR);

impl<ERR: Debug> Display for WrappingError<ERR> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        writeln!(f, "WrappingError({:?})", self.0)
    }
}

impl<ERR: Debug> Error for WrappingError<ERR> {}

impl<ERR: Debug> embedded_hal::i2c::Error for WrappingError<ERR> {
    fn kind(&self) -> ErrorKind {
        ErrorKind::Other
    }
}

impl<ERR: Debug> embedded_hal::pwm::Error for WrappingError<ERR> {
    fn kind(&self) -> embedded_hal::pwm::ErrorKind {
        embedded_hal::pwm::ErrorKind::Other
    }
}
