Skip to content

Commit

Permalink
added missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
pompon0 committed Nov 29, 2023
1 parent d07e4ee commit 1ff01e2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions node/libs/concurrency/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! Generalization of anyhow::Context to more structured errors.
use std::fmt::Display;

/// Trait complementary to anyhow::Context which allows for
/// adding context to error types which contain anyhow::Error.
pub trait Wrap: Sized {
/// Appends context `c` to the error.
fn wrap<C: Display + Send + Sync + 'static>(self, c: C) -> Self {
self.with_wrap(|| c)
}
/// Appends context `f()` to the error.
fn with_wrap<C: Display + Send + Sync + 'static, F: FnOnce() -> C>(self, f: F) -> Self;
}

impl<T, E: Wrap> Wrap for Result<T, E> {
fn with_wrap<C: Display + Send + Sync + 'static, F: FnOnce() -> C>(self, f: F) -> Self {
self.map_err(|err| err.with_wrap(f))
}
}

0 comments on commit 1ff01e2

Please sign in to comment.