bmp180_driver/
error.rs

1use std::error::Error;
2use std::fmt::{Debug, Display, Formatter, Pointer};
3
4/// Represents custom errors that can occur during BMP180 operations.
5#[derive(Debug)]
6pub enum CustomError<T> {
7    /// Indicates that the calibration data read from the sensor is invalid or corrupted.
8    InvalidCalibrationData,
9
10    /// Indicates that the device identifier read from the sensor does not match the expected value.
11    InvalidDeviceIdentifier,
12
13    /// Represents an I2C communication error encapsulating the inner error type `T`.
14    I2c(T),
15}
16
17impl<T> Display for CustomError<T> {
18    fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
19        match self {
20            CustomError::InvalidCalibrationData => write!(formatter, "Invalid calibration coefficients."),
21            CustomError::InvalidDeviceIdentifier => write!(formatter, "Invalid device identifier."),
22            CustomError::I2c(error) => error.fmt(formatter),
23        }
24    }
25}
26
27impl<T: Debug> Error for CustomError<T> {}
28
29impl<T> From<T> for CustomError<T> {
30    fn from(error: T) -> Self {
31        CustomError::I2c(error)
32    }
33}