this repo has no description
at main 53 lines 1.5 kB view raw
1use std::fmt::{Display, Formatter}; 2 3/// The Result type used throughout 4pub type Result<T, E = Error> = std::result::Result<T, E>; 5 6/// All errors that can be encountered when running 7#[derive(Debug)] 8pub enum Error { 9 // #[error("xcb returned a screen that doesn't exist")] 10 NoSuchScreen, 11 12 // #[error("another wm is running")] 13 OtherWMRunning, 14 15 // #[error("generic xcb error: {0}")] 16 Xcb(xcb::Error), 17 18 // #[error("connection error: {0}")] 19 Connection(xcb::ConnError), 20 21 // #[error("protocol error: {0}")] 22 Protocol(xcb::ProtocolError), 23} 24 25impl std::error::Error for Error {} 26 27impl Display for Error { 28 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { 29 match self { 30 Self::NoSuchScreen => write!(f, "xcb returned a screen that doesn't exist"), 31 Self::OtherWMRunning => write!(f, "another window manager is running"), 32 Self::Xcb(e) => write!(f, "generic xcb error: {e}"), 33 Self::Connection(e) => write!(f, "connection error: {e}"), 34 Self::Protocol(e) => write!(f, "protocol error: {e}"), 35 } 36 } 37} 38 39impl From<xcb::Error> for Error { 40 fn from(e: xcb::Error) -> Self { 41 Self::Xcb(e) 42 } 43} 44impl From<xcb::ConnError> for Error { 45 fn from(e: xcb::ConnError) -> Self { 46 Self::Connection(e) 47 } 48} 49impl From<xcb::ProtocolError> for Error { 50 fn from(e: xcb::ProtocolError) -> Self { 51 Self::Protocol(e) 52 } 53}