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
51
52
53
54
55
56
57
58
59
60
61
62
extern crate libc;
#[macro_use] extern crate quick_error;
#[cfg(feature = "libnv")] extern crate libnv_sys;
#[cfg(feature = "nvpair")]
extern crate nvpair_sys;
#[cfg(feature = "libnv")] pub mod libnv;
#[cfg(feature = "nvpair")] pub mod nvpair;
use std::{ffi::NulError, io};
quick_error! {
#[derive(Debug)]
pub enum NvError {
InvalidString(err: NulError) {
from()
}
NativeError(code: i32) {}
AlreadySet {}
NotFound {}
OutOfMemory {}
Io(err: io::Error) {}
OperationNotSupported {}
InvalidStringEncoding(err: std::str::Utf8Error) {
from()
}
}
}
impl NvError {
pub(crate) fn from_errno(errno: i32) -> Self {
match errno {
libc::ENOENT => NvError::NotFound,
libc::ENOMEM => NvError::OutOfMemory,
45 => NvError::OperationNotSupported,
n => NvError::Io(io::Error::from_raw_os_error(n)),
}
}
}
pub type NvResult<T> = Result<T, NvError>;