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_debug_err.rs
Normal file
36
src/core/result/log_debug_err.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use std::fmt;
|
||||
|
||||
use tracing::Level;
|
||||
|
||||
use super::{DebugInspect, Result};
|
||||
use crate::error;
|
||||
|
||||
pub trait LogDebugErr<T, E>
|
||||
where
|
||||
E: fmt::Debug,
|
||||
{
|
||||
#[must_use]
|
||||
fn err_debug_log(self, level: Level) -> Self;
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
fn log_debug_err(self) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
self.err_debug_log(Level::ERROR)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, E> LogDebugErr<T, E> for Result<T, E>
|
||||
where
|
||||
E: fmt::Debug,
|
||||
{
|
||||
#[inline]
|
||||
fn err_debug_log(self, level: Level) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
self.debug_inspect_err(|error| error::inspect_debug_log_level(&error, level))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue