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