rabbitmq_stream_protocol/
utils.rs

1pub trait TupleMapperFirst<Input, Output, Result>
2where
3    Self: Sized,
4{
5    fn map_first(self, mapper: impl Fn(Input) -> Output) -> Result;
6}
7
8pub trait TupleMapperSecond<Input, Output, Result>
9where
10    Self: Sized,
11{
12    fn map_second(self, mapper: impl FnOnce(Input) -> Output) -> Result;
13}
14
15impl<S, E, I, O> TupleMapperFirst<I, O, Result<(O, S), E>> for Result<(I, S), E> {
16    fn map_first(self, mapper: impl Fn(I) -> O) -> Result<(O, S), E> {
17        self.map(|(first, second)| (mapper(first), second))
18    }
19}
20
21impl<S, E, I, O> TupleMapperSecond<I, O, Result<(S, O), E>> for Result<(S, I), E> {
22    fn map_second(self, mapper: impl FnOnce(I) -> O) -> Result<(S, O), E> {
23        self.map(|(first, second)| (first, mapper(second)))
24    }
25}