based/src/result.rs

19 lines
547 B
Rust
Raw Normal View History

2024-12-17 23:28:43 +01:00
pub trait LogAndIgnore {
fn log_and_ignore(self, msg: &str);
}
impl<T, E: std::fmt::Debug> LogAndIgnore for Result<T, E> {
/// Handles the result by ignoring and logging it if it contains an error.
///
/// If the result is `Ok`, does nothing.
/// If the result is `Err(e)`
/// logs the message provided (`msg`) along with the error.
fn log_and_ignore(self, msg: &str) {
match self {
Ok(_) => {}
Err(e) => {
log::error!("{msg} : {:?}", e);
}
}
}
}