1use ffi;
7use std;
8
9#[derive(Debug)]
11pub enum Error {
12 FromAPI(String, ffi::c_int),
14
15 NulError(std::ffi::NulError),
17
18 InconsitentDims,
20}
21
22impl From<std::ffi::NulError> for Error {
23 fn from(err: std::ffi::NulError) -> Error { Error::NulError(err) }
24}
25
26impl std::fmt::Display for Error {
27 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
28 match *self {
29 Error::FromAPI(ref message, code) => write!(f, "Error from API: {} ({})", message, code),
30 Error::InconsitentDims => write!(f, "Inconsistent argument dimensions"),
31 Error::NulError(ref err) => write!(f, "NulError: {}", err),
32 }
33 }
34}
35
36impl std::error::Error for Error {
37 fn description(&self) -> &str {
38 match *self {
39 Error::FromAPI(..) => "error from C API",
40 Error::NulError(ref err) => err.description(),
41 Error::InconsitentDims => "Inconsistent argument dimensions",
42 }
43 }
44}
45
46
47pub type Result<T> = std::result::Result<T, Error>;