collenchyma 0.0.8

high-performance computation on any hardware
Documentation
//! Defines the general set of error types in Collenchyma.

use std::{error, fmt};

#[derive(Debug)]
/// Defines the set of available Collenchyma error types.
pub enum Error {
    /// Failure related to the Framework implementation.
    Framework(::framework::Error),
    /// Failure related to the Tensor.
    Tensor(::tensor::Error),
    /// Failure at Plugin Operation.
    Plugin(::plugin::Error),
    /// Failure related to a Device.
    Device(::device::Error),
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            Error::Framework(ref err) => write!(f, "Framwork error: {}", err),
            Error::Tensor(ref err) => write!(f, "Tensor error: {}", err),
            Error::Plugin(ref err) => write!(f, "Plugin error: {}", err),
            Error::Device(ref err) => write!(f, "Device error: {}", err),
        }
    }
}

impl error::Error for Error {
    fn description(&self) -> &str {
        match *self {
            Error::Framework(ref err) => err.description(),
            Error::Tensor(ref err) => err.description(),
            Error::Plugin(ref err) => err.description(),
            Error::Device(ref err) => err.description(),
        }
    }

    fn cause(&self) -> Option<&error::Error> {
        match *self {
            Error::Framework(ref err) => Some(err),
            Error::Tensor(ref err) => Some(err),
            Error::Plugin(ref err) => Some(err),
            Error::Device(ref err) => Some(err),
        }
    }
}