gpurs/
error.rs

1use std::fmt;
2use std::error::Error;
3
4#[cfg(feature = "gpu_accel")]
5use opencl3::error_codes::ClError;
6
7/// Error enum for gpurs crate
8#[derive(Debug)]
9pub enum Jeeperr {
10    /// Too many or too few arguments provided
11    ArgumentError,
12    /// Invalid matrix dimensions for requested operation
13    DimensionError,
14    /// Invalid index for requested operation
15    IndexError,
16    /// Calculator and Handler have inconsistent memory
17    MemoryError,
18    /// Invalid output type
19    OutputError,
20    /// ClError wrapper
21    #[cfg(feature = "gpu_accel")] ClError(ClError),
22    /// Generic error string wrapper
23    Error(String)
24}
25
26impl fmt::Display for Jeeperr {
27    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
28        match self {
29            Jeeperr::ArgumentError =>
30                write!(f, "Too many or too few arguments provided"),
31            Jeeperr::DimensionError =>
32                write!(f, "Invalid matrix dimensions for requested operation"),
33            Jeeperr::IndexError =>
34                write!(f, "Invalid index for requested operation"),
35            Jeeperr::MemoryError =>
36                write!(f, "Calculator and Handler have inconsistent memory"),
37            Jeeperr::OutputError =>
38                write!(f, "Invalid output type"),
39            #[cfg(feature = "gpu_accel")] Jeeperr::ClError(error) =>
40                write!(f, "{}", error),
41            Jeeperr::Error(error) =>
42                write!(f, "{}", error)
43        }
44    }
45}
46
47impl Error for Jeeperr {}
48
49#[cfg(feature = "gpu_accel")]
50impl From<ClError> for Jeeperr {
51    fn from(err: ClError) -> Self {
52        Jeeperr::ClError(err)
53    }
54}