1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
use anyhow::*;

pub struct AnyError<E>(E);

impl<E: core::fmt::Debug> AnyError<E> {
    pub fn into(error: E) -> anyhow::Error {
        anyhow!("Error: {:?}", error)
    }

    pub fn wrap<R, C>(closure: C) -> Result<R>
    where
        C: FnOnce() -> Result<R, E>,
    {
        closure().map_err(Self::into)
    }
}