use std::fmt::{Display, Formatter}; /// The Result type used throughout pub type Result = std::result::Result; /// All errors that can be encountered when running #[derive(Debug)] pub enum Error { // #[error("xcb returned a screen that doesn't exist")] NoSuchScreen, // #[error("another wm is running")] OtherWMRunning, // #[error("generic xcb error: {0}")] Xcb(xcb::Error), // #[error("connection error: {0}")] Connection(xcb::ConnError), // #[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 { Self::NoSuchScreen => write!(f, "xcb returned a screen that doesn't exist"), Self::OtherWMRunning => write!(f, "another window manager is running"), Self::Xcb(e) => write!(f, "generic xcb error: {e}"), Self::Connection(e) => write!(f, "connection error: {e}"), Self::Protocol(e) => write!(f, "protocol error: {e}"), } } } impl From for Error { fn from(e: xcb::Error) -> Self { Self::Xcb(e) } } impl From for Error { fn from(e: xcb::ConnError) -> Self { Self::Connection(e) } } impl From for Error { fn from(e: xcb::ProtocolError) -> Self { Self::Protocol(e) } }