1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
use core::fmt; pub type Result<T, I2cError> = core::result::Result<T, Error<I2cError>>; #[derive(Debug)] pub enum Error<I2cError> { InvalidDevice(u8), InvalidMeasurementTime(u8), I2cError(I2cError), } impl<I2cError> fmt::Display for Error<I2cError> where I2cError: fmt::Debug, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use Error::*; match self { InvalidDevice(v) => write!(f, "Invalid device with id {}", v), InvalidMeasurementTime(v) => write!( f, "Invalid measurement time: {}ms. Allowed range: [31-254]ms.", v ), I2cError(e) => fmt::Debug::fmt(&e, f), } } }