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
use ffi;
use glib_ffi;
use glib::error::ErrorDomain;
use glib::translate::*;
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum ResourceError {
NotFound,
Internal,
#[doc(hidden)]
__Nonexhaustive(()),
}
#[doc(hidden)]
impl ToGlib for ResourceError {
type GlibType = ffi::GResourceError;
fn to_glib(&self) -> ffi::GResourceError {
match *self {
ResourceError::NotFound => ffi::G_RESOURCE_ERROR_NOT_FOUND,
ResourceError::Internal => ffi::G_RESOURCE_ERROR_INTERNAL,
ResourceError::__Nonexhaustive(_) => panic!(),
}
}
}
#[doc(hidden)]
impl FromGlib<ffi::GResourceError> for ResourceError {
fn from_glib(value: ffi::GResourceError) -> Self {
match value {
ffi::G_RESOURCE_ERROR_NOT_FOUND => ResourceError::NotFound,
ffi::G_RESOURCE_ERROR_INTERNAL => ResourceError::Internal,
}
}
}
impl ErrorDomain for ResourceError {
fn domain() -> glib_ffi::GQuark {
unsafe { ffi::g_resource_error_quark() }
}
fn code(self) -> i32 {
self.to_glib() as i32
}
fn from(code: i32) -> Option<Self> {
match code {
x if x == ffi::G_RESOURCE_ERROR_NOT_FOUND as i32 => Some(ResourceError::NotFound),
x if x == ffi::G_RESOURCE_ERROR_INTERNAL as i32 => Some(ResourceError::Internal),
_ => Some(ResourceError::__Nonexhaustive(())),
}
}
}