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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! 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),
        }
    }
}