This commit is contained in:
parent
00bb6f152d
commit
86dbdcf75d
1 changed files with 23 additions and 0 deletions
|
@ -30,3 +30,26 @@ impl<T, E: std::fmt::Debug> LogAndIgnore for Result<T, E> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait LogNoneAndPass {
|
||||||
|
fn log_warn_none_and_pass(self, msg: impl Fn() -> String) -> Self;
|
||||||
|
fn log_err_none_and_pass(self, msg: impl Fn() -> String) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> LogNoneAndPass for Option<T> {
|
||||||
|
fn log_warn_none_and_pass(self, msg: impl Fn() -> String) -> Option<T> {
|
||||||
|
if matches!(self, None) {
|
||||||
|
log::warn!("{}", msg());
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn log_err_none_and_pass(self, msg: impl Fn() -> String) -> Option<T> {
|
||||||
|
if matches!(self, None) {
|
||||||
|
log::error!("{}", msg());
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue