1pub struct MapErr<R, F> {
11    pub(crate) inner: R,
12    pub(crate) mapper: F,
13    _private: (),
14}
15
16impl<R, F> MapErr<R, F> {
17    #[must_use]
20    pub fn new(inner: R, mapper: F) -> Self {
21        Self {
22            inner,
23            mapper,
24            _private: (),
25        }
26    }
27}
28
29#[macro_export]
32macro_rules! repository_impl {
33    ($repo_trait:ident:
34        $(
35            async fn $method:ident (
36                &mut self
37                $(, $arg:ident: $arg_ty:ty )*
38                $(,)?
39            ) -> Result<$ret_ty:ty, Self::Error>;
40        )*
41    ) => {
42        #[::async_trait::async_trait]
43        impl<R: ?Sized> $repo_trait for ::std::boxed::Box<R>
44        where
45            R: $repo_trait,
46        {
47            type Error = <R as $repo_trait>::Error;
48
49            $(
50                async fn $method (&mut self $(, $arg: $arg_ty)*) -> Result<$ret_ty, Self::Error> {
51                    (**self).$method ( $($arg),* ).await
52                }
53            )*
54        }
55
56        #[::async_trait::async_trait]
57        impl<R, F, E> $repo_trait for $crate::MapErr<R, F>
58        where
59            R: $repo_trait,
60            F: FnMut(<R as $repo_trait>::Error) -> E + ::std::marker::Send + ::std::marker::Sync,
61        {
62            type Error = E;
63
64            $(
65                async fn $method (&mut self $(, $arg: $arg_ty)*) -> Result<$ret_ty, Self::Error> {
66                    self.inner.$method ( $($arg),* ).await.map_err(&mut self.mapper)
67                }
68            )*
69        }
70    };
71}