rspace_traits/ops/
apply.rs1pub trait Apply<Rhs> {
9 type Output;
10
11 fn apply(&self, rhs: Rhs) -> Self::Output;
12}
13pub trait ApplyOnce<Rhs> {
16 type Output;
17
18 fn apply_once(self, rhs: Rhs) -> Self::Output;
19}
20pub trait ApplyMut<Rhs> {
23 type Output;
24
25 fn apply_mut(&mut self, rhs: Rhs) -> Self::Output;
26}
27
28pub trait TryApply<Rhs> {
29 type Output;
30 type Error;
31
32 fn try_apply(&self, rhs: Rhs) -> Result<Self::Output, Self::Error>;
33}
34
35pub trait TryApplyOnce<Rhs> {
36 type Output;
37 type Error;
38
39 fn try_apply_once(self, rhs: Rhs) -> Result<Self::Output, Self::Error>;
40}
41
42pub trait TryApplyMut<Rhs> {
43 type Output;
44 type Error;
45
46 fn try_apply_mut(&mut self, rhs: Rhs) -> Result<Self::Output, Self::Error>;
47}
48
49impl<A, X, Y> TryApply<X> for A
53where
54 A: Apply<X, Output = Y>,
55{
56 type Output = A::Output;
57 type Error = core::convert::Infallible;
58
59 fn try_apply(&self, rhs: X) -> Result<Self::Output, Self::Error> {
60 Ok(self.apply(rhs))
61 }
62}
63
64impl<A, X, Y> TryApplyOnce<X> for A
65where
66 A: ApplyOnce<X, Output = Y>,
67{
68 type Output = A::Output;
69 type Error = core::convert::Infallible;
70
71 fn try_apply_once(self, rhs: X) -> Result<Self::Output, Self::Error> {
72 Ok(self.apply_once(rhs))
73 }
74}
75
76impl<A, X, Y> TryApplyMut<X> for A
77where
78 A: ApplyMut<X, Output = Y>,
79{
80 type Output = A::Output;
81 type Error = core::convert::Infallible;
82
83 fn try_apply_mut(&mut self, rhs: X) -> Result<Self::Output, Self::Error> {
84 Ok(self.apply_mut(rhs))
85 }
86}