diff options
author | tcmal <me@aria.rip> | 2024-06-09 17:34:45 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-06-09 17:34:45 +0100 |
commit | 124e6878b1de561f4bc3fccea768203821c88469 (patch) | |
tree | ff46ede6bc720148402841bfaad6d850ec900ab0 /src/error.rs | |
parent | 66e3423828892a72e5e525f2dc8d5ad91e634445 (diff) |
minor cleanup
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/src/error.rs b/src/error.rs index 3086204..dcbcfe9 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,23 +1,53 @@ -use thiserror::Error; +use std::fmt::{Display, Formatter}; /// The Result type used throughout pub type Result<T, E = Error> = std::result::Result<T, E>; /// All errors that can be encountered when running -#[derive(Debug, Error)] +#[derive(Debug)] pub enum Error { - #[error("xcb returned screen that doesn't exist")] + // #[error("xcb returned a screen that doesn't exist")] NoSuchScreen, - #[error("other wm is running")] + // #[error("another wm is running")] OtherWMRunning, - #[error("generic xcb error: {0}")] - Xcb(#[from] xcb::Error), + // #[error("generic xcb error: {0}")] + Xcb(xcb::Error), - #[error("connection error: {0}")] - Connection(#[from] xcb::ConnError), + // #[error("connection error: {0}")] + Connection(xcb::ConnError), - #[error("protocol error: {0}")] - Protocol(#[from] xcb::ProtocolError), + // #[error("protocol error: {0}")] + Protocol(xcb::ProtocolError), +} + +impl std::error::Error for Error {} + +impl Display for Error { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + Error::NoSuchScreen => write!(f, "xcb returned a screen that doesn't exist"), + Error::OtherWMRunning => write!(f, "another window manager is running"), + Error::Xcb(e) => write!(f, "generic xcb error: {}", e), + Error::Connection(e) => write!(f, "connection error: {}", e), + Error::Protocol(e) => write!(f, "protocol error: {}", e), + } + } +} + +impl From<xcb::Error> for Error { + fn from(e: xcb::Error) -> Self { + Self::Xcb(e) + } +} +impl From<xcb::ConnError> for Error { + fn from(e: xcb::ConnError) -> Self { + Self::Connection(e) + } +} +impl From<xcb::ProtocolError> for Error { + fn from(e: xcb::ProtocolError) -> Self { + Self::Protocol(e) + } } |