move core result into core utils

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2024-10-24 01:31:30 +00:00
committed by strawberry
parent 5cb0a5f676
commit c769fcc347
12 changed files with 2 additions and 3 deletions
+60
View File
@@ -0,0 +1,60 @@
use std::fmt;
use tracing::Level;
use super::Result;
use crate::error;
pub trait ErrLog<T, E>
where
E: fmt::Display,
{
fn log_err(self, level: Level) -> Self;
fn err_log(self) -> Self
where
Self: Sized,
{
self.log_err(Level::ERROR)
}
}
pub trait ErrDebugLog<T, E>
where
E: fmt::Debug,
{
fn log_err_debug(self, level: Level) -> Self;
fn err_debug_log(self) -> Self
where
Self: Sized,
{
self.log_err_debug(Level::ERROR)
}
}
impl<T, E> ErrLog<T, E> for Result<T, E>
where
E: fmt::Display,
{
#[inline]
fn log_err(self, level: Level) -> Self
where
Self: Sized,
{
self.inspect_err(|error| error::inspect_log_level(&error, level))
}
}
impl<T, E> ErrDebugLog<T, E> for Result<T, E>
where
E: fmt::Debug,
{
#[inline]
fn log_err_debug(self, level: Level) -> Self
where
Self: Sized,
{
self.inspect_err(|error| error::inspect_debug_log_level(&error, level))
}
}