diff options
Diffstat (limited to 'src/error.rs')
| -rw-r--r-- | src/error.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..81c69e5 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,35 @@ +use std::fmt::{ self, Display }; + +#[derive(Debug)] +pub struct Error(String); +pub type Result<T> = std::result::Result<T, Error>; + + +impl Display for Error { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(formatter, "Error: {}", self.0) + } +} + +impl From<xcb::Error> for Error { + fn from(error: xcb::Error) -> Error { + match error { + xcb::Error::Connection(error) => error.into(), + xcb::Error::Protocol(error) => error.into(), + } + } +} + +impl From<xcb::ConnError> for Error { + fn from(error: xcb::ConnError) -> Error { + Error(format!("X connection: {}", error)) + } +} + +impl From<xcb::ProtocolError> for Error { + fn from(error: xcb::ProtocolError) -> Error { + Error(format!("X protocol: {}", error)) + } +} + + |