use std::fmt::{ self, Display }; #[derive(Debug)] pub struct Error(String); pub type Result = std::result::Result; impl Error { pub fn log(&self) { println!("Error: {}", self); } } impl Display for Error { fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { write!(formatter, "Error: {}", self.0) } } impl From> for Error { fn from(error: std::sync::PoisonError) -> Error { Error(format!("Lock poisoned: {}", error)) } } impl From for Error { fn from(error: async_channel::RecvError) -> Error { Error(format!("Channel receive error: {}", error)) } } impl From> for Error { fn from(error: async_channel::SendError) -> Error { Error(format!("Channel send error: {}", error)) } } impl From for Error { fn from(error: xcb::Error) -> Error { match error { xcb::Error::Connection(error) => error.into(), xcb::Error::Protocol(error) => error.into(), } } } impl From for Error { fn from(error: xcb::ConnError) -> Error { Error(format!("X connection: {}", error)) } } impl From for Error { fn from(error: xcb::ProtocolError) -> Error { Error(format!("X protocol: {}", error)) } } pub fn log_and_ignore_errors>( result: std::result::Result) { match result { Ok(_) => (), Err(error) => Into::::into(error).log() } }