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
48
49
50
use ffi;
use std;
#[derive(Debug)]
pub enum Error {
FromAPI(String, ffi::c_int),
NulError(std::ffi::NulError),
InconsitentDims,
}
impl From<std::ffi::NulError> for Error {
fn from(err: std::ffi::NulError) -> Error { Error::NulError(err) }
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
Error::FromAPI(ref message, code) => write!(f, "Error from API: {} ({})", message, code),
Error::InconsitentDims => write!(f, "Inconsistent argument dimensions"),
Error::NulError(ref err) => write!(f, "NulError: {}", err),
}
}
}
impl std::error::Error for Error {
fn description(&self) -> &str {
match *self {
Error::FromAPI(..) => "error from C API",
Error::NulError(ref err) => err.description(),
Error::InconsitentDims => "Inconsistent argument dimensions",
}
}
}
pub type Result<T> = std::result::Result<T, Error>;