diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-11-21 14:42:14 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-11-21 14:52:48 -0700 |
| commit | bfd0d9e48acdbca5758b0d64c3d30f06f008a3b9 (patch) | |
| tree | 2642c8a186e429a2215a745878fa5d198dd21233 /src/error.rs | |
| parent | f6cb132d4e026db2b5fcb467bca50eab1c50f04c (diff) | |
plist parsing
Force-Push: yes Change-Id: I79789ad2bd761e27dd2437bec381e550e99029a7
Diffstat (limited to 'src/error.rs')
| -rw-r--r-- | src/error.rs | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/error.rs b/src/error.rs index b3bb460..390d6da 100644 --- a/src/error.rs +++ b/src/error.rs @@ -7,7 +7,11 @@ pub type Result<T> = std::result::Result<T, Error>; impl Error { pub fn log(&self) { - println!("Error: {}", self); + println!("{}", self); + } + + pub fn custom(text: &str) -> Self { + Error(text.to_string()) } } @@ -20,7 +24,13 @@ impl Display for Error { impl From<std::io::Error> for Error { fn from(error: std::io::Error) -> Error { - Error(format!("I/O error: {}", error)) + Error(format!("I/O: {}", error)) + } +} + +impl From<std::num::ParseIntError> for Error { + fn from(error: std::num::ParseIntError) -> Error { + Error(format!("integer syntax: {}", error)) } } @@ -32,19 +42,19 @@ impl<T> From<std::sync::PoisonError<T>> for Error { impl From<async_channel::RecvError> for Error { fn from(error: async_channel::RecvError) -> Error { - Error(format!("Channel receive error: {}", error)) + Error(format!("Channel receive: {}", error)) } } impl<T> From<async_channel::SendError<T>> for Error { fn from(error: async_channel::SendError<T>) -> Error { - Error(format!("Channel send error: {}", error)) + Error(format!("Channel send: {}", error)) } } impl From<rustix::io::Errno> for Error { fn from(error: rustix::io::Errno) -> Error { - Error(format!("Unix system-call error: {}", error)) + Error(format!("Unix system-call: {}", error)) } } @@ -70,6 +80,12 @@ impl From<xcb::ProtocolError> for Error { } } +impl From<xml::reader::Error> for Error { + fn from(error: xml::reader::Error) -> Error { + Error(format!("XML parsing: {}", error)) + } +} + pub fn log_and_ignore_errors<T, E: Into<Error>>( result: std::result::Result<T, E>) |