about summary refs log tree commit diff
path: root/src/error.rs
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-11-15 22:30:48 -0700
committerIrene Knapp <ireneista@irenes.space>2026-11-15 22:30:48 -0700
commit73296ede1fc7b1abde65546a71aef5a988c21e8d (patch)
treef19bdf87f74663f207975353b3b90420084fc2fa /src/error.rs
parent5b488f558ccaca6ac35edda0366d74b9126285e3 (diff)
multi-threaded. more dependencies :( the clock runs now!
some unfortunate reliance on exact sequencing, which needs to be cleaned up

Force-Push: yes
Change-Id: I833dd0dd5047e3c2f04203e80e3fd722e36bf252
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs
index 81c69e5..8537d2e 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -5,12 +5,37 @@ pub struct Error(String);
 pub type Result<T> = std::result::Result<T, Error>;
 
 
+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<T> From<std::sync::PoisonError<T>> for Error {
+  fn from(error: std::sync::PoisonError<T>) -> Error {
+    Error(format!("Lock poisoned: {}", error))
+  }
+}
+
+impl From<async_channel::RecvError> for Error {
+  fn from(error: async_channel::RecvError) -> Error {
+    Error(format!("Channel receive error: {}", error))
+  }
+}
+
+impl<T> From<async_channel::SendError<T>> for Error {
+  fn from(error: async_channel::SendError<T>) -> Error {
+    Error(format!("Channel send error: {}", error))
+  }
+}
+
 impl From<xcb::Error> for Error {
   fn from(error: xcb::Error) -> Error {
     match error {
@@ -33,3 +58,12 @@ impl From<xcb::ProtocolError> for Error {
 }
 
 
+pub fn log_and_ignore_errors<T, E: Into<Error>>(
+           result: std::result::Result<T, E>)
+{
+  match result {
+    Ok(_) => (),
+    Err(error) => Into::<Error>::into(error).log()
+  }
+}
+