add err log trait to Result
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
3d4b0f10a5
commit
aa265f7ca4
5 changed files with 163 additions and 6 deletions
36
src/core/result/log_err.rs
Normal file
36
src/core/result/log_err.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use std::fmt;
|
||||
|
||||
use tracing::Level;
|
||||
|
||||
use super::Result;
|
||||
use crate::error;
|
||||
|
||||
pub trait LogErr<T, E>
|
||||
where
|
||||
E: fmt::Display,
|
||||
{
|
||||
#[must_use]
|
||||
fn err_log(self, level: Level) -> Self;
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
fn log_err(self) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
self.err_log(Level::ERROR)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, E> LogErr<T, E> for Result<T, E>
|
||||
where
|
||||
E: fmt::Display,
|
||||
{
|
||||
#[inline]
|
||||
fn err_log(self, level: Level) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
self.inspect_err(|error| error::inspect_log_level(&error, level))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue