1 | /// An error type representing the failure to load libwayland |
2 | #[derive (Debug)] |
3 | pub struct NoWaylandLib; |
4 | |
5 | impl std::error::Error for NoWaylandLib {} |
6 | |
7 | impl std::fmt::Display for NoWaylandLib { |
8 | #[cfg_attr (coverage, coverage(off))] |
9 | fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { |
10 | f.write_str(data:"could not load libwayland-client.so" ) |
11 | } |
12 | } |
13 | |
14 | /// An error that can occur when using a Wayland connection |
15 | #[derive (Debug)] |
16 | pub enum WaylandError { |
17 | /// The connection encountered an IO error |
18 | Io(std::io::Error), |
19 | /// The connection encountered a protocol error |
20 | Protocol(crate::protocol::ProtocolError), |
21 | } |
22 | |
23 | impl std::error::Error for WaylandError { |
24 | #[cfg_attr (coverage, coverage(off))] |
25 | fn cause(&self) -> Option<&dyn std::error::Error> { |
26 | match self { |
27 | Self::Io(e: &Error) => Some(e), |
28 | Self::Protocol(e: &ProtocolError) => Some(e), |
29 | } |
30 | } |
31 | } |
32 | |
33 | impl std::fmt::Display for WaylandError { |
34 | #[cfg_attr (coverage, coverage(off))] |
35 | fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { |
36 | match self { |
37 | Self::Io(e: &Error) => write!(f, "Io error: {}" , e), |
38 | Self::Protocol(e: &ProtocolError) => std::fmt::Display::fmt(self:e, f), |
39 | } |
40 | } |
41 | } |
42 | |
43 | impl Clone for WaylandError { |
44 | #[cfg_attr (coverage, coverage(off))] |
45 | fn clone(&self) -> Self { |
46 | match self { |
47 | Self::Protocol(e: &ProtocolError) => Self::Protocol(e.clone()), |
48 | Self::Io(e: &Error) => { |
49 | if let Some(code: i32) = e.raw_os_error() { |
50 | Self::Io(std::io::Error::from_raw_os_error(code)) |
51 | } else { |
52 | Self::Io(std::io::Error::new(e.kind(), error:"" )) |
53 | } |
54 | } |
55 | } |
56 | } |
57 | } |
58 | |
59 | impl From<crate::protocol::ProtocolError> for WaylandError { |
60 | #[cfg_attr (coverage, coverage(off))] |
61 | fn from(err: crate::protocol::ProtocolError) -> Self { |
62 | Self::Protocol(err) |
63 | } |
64 | } |
65 | |
66 | impl From<std::io::Error> for WaylandError { |
67 | #[cfg_attr (coverage, coverage(off))] |
68 | fn from(err: std::io::Error) -> Self { |
69 | Self::Io(err) |
70 | } |
71 | } |
72 | |
73 | /// An error generated when trying to act on an invalid `ObjectId`. |
74 | #[derive (Clone, Debug)] |
75 | pub struct InvalidId; |
76 | |
77 | impl std::error::Error for InvalidId {} |
78 | |
79 | impl std::fmt::Display for InvalidId { |
80 | #[cfg_attr (coverage, coverage(off))] |
81 | fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { |
82 | write!(f, "Invalid ObjectId" ) |
83 | } |
84 | } |
85 | |