core_crypto/error/
wrapper.rs

1/// A wrapped operation failed, but we captured some context about what was happening
2#[derive(Debug, thiserror::Error)]
3#[error("{context}")]
4pub struct WrappedContextualError<T> {
5    /// What was happening in the caller
6    pub context: &'static str,
7    /// What happened
8    #[source]
9    pub source: T,
10}
11
12impl<T> WrappedContextualError<T> {
13    pub fn wrap<E>(context: &'static str) -> impl FnOnce(E) -> Self
14    where
15        E: Into<T>,
16    {
17        move |source| Self {
18            source: source.into(),
19            context,
20        }
21    }
22}