1use error::ErrorDomain;
6use glib_sys;
7use translate::from_glib;
8use Quark;
9
10#[derive(Clone, Copy, Debug, PartialEq, Eq)]
11pub enum FileError {
12 Exist,
13 Isdir,
14 Acces,
15 Nametoolong,
16 Noent,
17 Notdir,
18 Nxio,
19 Nodev,
20 Rofs,
21 Txtbsy,
22 Fault,
23 Loop,
24 Nospc,
25 Nomem,
26 Mfile,
27 Nfile,
28 Badf,
29 Inval,
30 Pipe,
31 Again,
32 Intr,
33 Io,
34 Perm,
35 Nosys,
36 Failed,
37}
38
39impl ErrorDomain for FileError {
40 fn domain() -> Quark {
41 unsafe { from_glib(glib_sys::g_file_error_quark()) }
42 }
43
44 fn code(self) -> i32 {
45 use self::FileError::*;
46 match self {
47 Exist => glib_sys::G_FILE_ERROR_EXIST as i32,
48 Isdir => glib_sys::G_FILE_ERROR_ISDIR as i32,
49 Acces => glib_sys::G_FILE_ERROR_ACCES as i32,
50 Nametoolong => glib_sys::G_FILE_ERROR_NAMETOOLONG as i32,
51 Noent => glib_sys::G_FILE_ERROR_NOENT as i32,
52 Notdir => glib_sys::G_FILE_ERROR_NOTDIR as i32,
53 Nxio => glib_sys::G_FILE_ERROR_NXIO as i32,
54 Nodev => glib_sys::G_FILE_ERROR_NODEV as i32,
55 Rofs => glib_sys::G_FILE_ERROR_ROFS as i32,
56 Txtbsy => glib_sys::G_FILE_ERROR_TXTBSY as i32,
57 Fault => glib_sys::G_FILE_ERROR_FAULT as i32,
58 Loop => glib_sys::G_FILE_ERROR_LOOP as i32,
59 Nospc => glib_sys::G_FILE_ERROR_NOSPC as i32,
60 Nomem => glib_sys::G_FILE_ERROR_NOMEM as i32,
61 Mfile => glib_sys::G_FILE_ERROR_MFILE as i32,
62 Nfile => glib_sys::G_FILE_ERROR_NFILE as i32,
63 Badf => glib_sys::G_FILE_ERROR_BADF as i32,
64 Inval => glib_sys::G_FILE_ERROR_INVAL as i32,
65 Pipe => glib_sys::G_FILE_ERROR_PIPE as i32,
66 Again => glib_sys::G_FILE_ERROR_AGAIN as i32,
67 Intr => glib_sys::G_FILE_ERROR_INTR as i32,
68 Io => glib_sys::G_FILE_ERROR_IO as i32,
69 Perm => glib_sys::G_FILE_ERROR_PERM as i32,
70 Nosys => glib_sys::G_FILE_ERROR_NOSYS as i32,
71 Failed => glib_sys::G_FILE_ERROR_FAILED as i32,
72 }
73 }
74
75 #[allow(clippy::cyclomatic_complexity)]
76 fn from(code: i32) -> Option<Self> {
77 use self::FileError::*;
78 match code {
79 x if x == glib_sys::G_FILE_ERROR_EXIST as i32 => Some(Exist),
80 x if x == glib_sys::G_FILE_ERROR_ISDIR as i32 => Some(Isdir),
81 x if x == glib_sys::G_FILE_ERROR_ACCES as i32 => Some(Acces),
82 x if x == glib_sys::G_FILE_ERROR_NAMETOOLONG as i32 => Some(Nametoolong),
83 x if x == glib_sys::G_FILE_ERROR_NOENT as i32 => Some(Noent),
84 x if x == glib_sys::G_FILE_ERROR_NOTDIR as i32 => Some(Notdir),
85 x if x == glib_sys::G_FILE_ERROR_NXIO as i32 => Some(Nxio),
86 x if x == glib_sys::G_FILE_ERROR_NODEV as i32 => Some(Nodev),
87 x if x == glib_sys::G_FILE_ERROR_ROFS as i32 => Some(Rofs),
88 x if x == glib_sys::G_FILE_ERROR_TXTBSY as i32 => Some(Txtbsy),
89 x if x == glib_sys::G_FILE_ERROR_FAULT as i32 => Some(Fault),
90 x if x == glib_sys::G_FILE_ERROR_LOOP as i32 => Some(Loop),
91 x if x == glib_sys::G_FILE_ERROR_NOSPC as i32 => Some(Nospc),
92 x if x == glib_sys::G_FILE_ERROR_NOMEM as i32 => Some(Nomem),
93 x if x == glib_sys::G_FILE_ERROR_MFILE as i32 => Some(Mfile),
94 x if x == glib_sys::G_FILE_ERROR_NFILE as i32 => Some(Nfile),
95 x if x == glib_sys::G_FILE_ERROR_BADF as i32 => Some(Badf),
96 x if x == glib_sys::G_FILE_ERROR_INVAL as i32 => Some(Inval),
97 x if x == glib_sys::G_FILE_ERROR_PIPE as i32 => Some(Pipe),
98 x if x == glib_sys::G_FILE_ERROR_AGAIN as i32 => Some(Again),
99 x if x == glib_sys::G_FILE_ERROR_INTR as i32 => Some(Intr),
100 x if x == glib_sys::G_FILE_ERROR_IO as i32 => Some(Io),
101 x if x == glib_sys::G_FILE_ERROR_PERM as i32 => Some(Perm),
102 x if x == glib_sys::G_FILE_ERROR_NOSYS as i32 => Some(Nosys),
103 x if x == glib_sys::G_FILE_ERROR_FAILED as i32 => Some(Failed),
104 _ => Some(Failed),
105 }
106 }
107}