ads1x15 0.5.0

I2C driver for the Texas Instruments ADS1015/ADS1115 ADC
//! Common error definitions.
use std::error;
use std::fmt;
use std::result;

use futures;
use i2cdev;
use tokio_timer;

/// A result returned by a driver operation.
pub type Result<A, D> = result::Result<A, Error<D>>;

/// An error generated by a driver operation.
pub enum Error<D>
where
    D: i2cdev::core::I2CDevice,
{
    /// An error originating from the I2C bus.
    I2C(D::Error),
    /// An error originating from the tokio timer infrastructure.
    Timer(tokio_timer::Error),
    /// An error because the operation was canceled.
    Canceled(futures::sync::oneshot::Canceled),
}

impl<D> fmt::Debug for Error<D>
where
    D: i2cdev::core::I2CDevice,
{
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            Error::I2C(ref e) => f.debug_tuple("I2C").field(e).finish(),
            Error::Timer(ref e) => f.debug_tuple("Timer").field(e).finish(),
            Error::Canceled(ref e) => f.debug_tuple("Canceled").field(e).finish(),
        }
    }
}

impl<D> fmt::Display for Error<D>
where
    D: i2cdev::core::I2CDevice,
{
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            Error::I2C(ref e) => write!(f, "i2c error: {}", e),
            Error::Timer(ref e) => write!(f, "timer error: {}", e),
            Error::Canceled(ref e) => write!(f, "canceled: {}", e),
        }
    }
}

impl<D> error::Error for Error<D> where D: i2cdev::core::I2CDevice {}