#[cfg(feature = "impls")]
use crate::{self as plog, error, ok};
use std::fmt::{Debug, Display};
pub trait ResultLog<T> {
fn log(self, _: T) -> Self;
fn show_ok(self, _: T) -> Self;
fn show_err(self, _: T) -> Self;
}
impl<T, U, N> ResultLog<N> for Result<T, U>
where
T: Debug,
U: Debug,
N: Display,
{
fn log(self, _name: N) -> Self {
#[cfg(feature = "impls")]
match self {
Ok(ref val) => ok!("{_name} succeed {val:?}"),
Err(ref err) => error!("{_name} was failed with {err:?}"),
}
self
}
fn show_err(self, _name: N) -> Self {
#[cfg(feature = "impls")]
if let Err(ref err) = self {
error!("{_name} was failed with {err:?}");
}
self
}
fn show_ok(self, _name: N) -> Self {
#[cfg(feature = "impls")]
if let Ok(ref val) = self {
ok!("{_name} succeed with {val:?}");
}
self
}
}