tuppipe/
also.rs

1use std::marker::PhantomData;
2
3use crate::Pipe;
4
5#[inline]
6pub const fn also<'value, P, T>(pipe: P) -> Also<'value, P, T>
7where
8    P: Pipe<&'value T, Output = ()>,
9{
10    Also {
11        _t: PhantomData,
12        pipe,
13    }
14}
15
16#[inline]
17pub fn also_mut<'value, P, T>(pipe: P) -> AlsoMut<'value, P, T>
18where
19    P: Pipe<&'value mut T, Output = ()>,
20{
21    AlsoMut {
22        _t: PhantomData,
23        pipe,
24    }
25}
26
27pub struct Also<'value, P, T>
28where
29    P: Pipe<&'value T, Output = ()>,
30{
31    _t: PhantomData<&'value T>,
32    pipe: P,
33}
34
35impl<'value, P, T> Pipe<&'value T> for Also<'value, P, T>
36where
37    P: for<'local> Pipe<&'local T, Output = ()>,
38{
39    type Output = &'value T;
40
41    #[inline]
42    fn complete(self, value: &'value T) -> Self::Output {
43        self.pipe.complete(value);
44        value
45    }
46}
47
48impl<'value, P, T> Pipe<&'value mut T> for Also<'value, P, T>
49where
50    P: for<'local> Pipe<&'local T, Output = ()>,
51{
52    type Output = &'value mut T;
53
54    #[inline]
55    fn complete(self, value: &'value mut T) -> Self::Output {
56        self.pipe.complete(value);
57        value
58    }
59}
60
61impl<P, T> Pipe<T> for Also<'_, P, T>
62where
63    P: for<'local> Pipe<&'local T, Output = ()>,
64{
65    type Output = T;
66
67    #[inline]
68    fn complete(self, value: T) -> Self::Output {
69        self.pipe.complete(&value);
70        value
71    }
72}
73
74pub struct AlsoMut<'value, P, T>
75where
76    P: Pipe<&'value mut T, Output = ()>,
77{
78    _t: PhantomData<&'value mut T>,
79    pipe: P,
80}
81
82impl<'value, P, T> Pipe<&'value mut T> for AlsoMut<'value, P, T>
83where
84    P: for<'local> Pipe<&'local mut T, Output = ()>,
85{
86    type Output = &'value mut T;
87
88    #[inline]
89    fn complete(self, value: &'value mut T) -> Self::Output {
90        self.pipe.complete(value);
91        value
92    }
93}
94
95impl<P, T> Pipe<T> for AlsoMut<'_, P, T>
96where
97    P: for<'local> Pipe<&'local mut T, Output = ()>,
98{
99    type Output = T;
100
101    #[inline]
102    fn complete(self, mut value: T) -> Self::Output {
103        self.pipe.complete(&mut value);
104        value
105    }
106}