Skip to content

Commit

Permalink
inlined
Browse files Browse the repository at this point in the history
  • Loading branch information
mkatychev committed Apr 9, 2024
1 parent f35b054 commit 1f94daa
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,16 @@ impl<T, E> LogError<T, E> for Result<T, E>
where
E: fmt::Debug,
{
#[inline]
#[track_caller]
fn log_err(self) {
if let Err(e) = self {
error!(err = ?e);
}
}

#[inline]
#[track_caller]
fn log_attached_err<A>(self, attachment: A)
where
A: fmt::Debug + Send + Sync + 'static,
Expand All @@ -473,6 +477,8 @@ where
error!(err = ?e, "{attachment:?}");
}
}
#[inline]
#[track_caller]
fn and_log(self, level: Level) -> Result<T, E> {
if let Err(err) = &self {
match level {
Expand All @@ -486,13 +492,17 @@ where
self
}

#[inline]
#[track_caller]
fn and_log_err(self) -> Result<T, E> {
if let Err(e) = &self {
error!(err = ?e);
}
self
}

#[inline]
#[track_caller]
fn and_attached_err<A>(self, attachment: A) -> Result<T, E>
where
A: fmt::Debug + Send + Sync + 'static,
Expand All @@ -502,6 +512,9 @@ where
}
self
}

#[inline]
#[track_caller]
fn on_err(self, op: impl FnOnce()) -> Result<T, E> {
op();
self
Expand Down

0 comments on commit 1f94daa

Please sign in to comment.