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 { 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 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) } }