1#[allow(unused)]
2use core::ops::{
3 Neg,
4 Add, AddAssign, Sub, SubAssign,
5 Mul, MulAssign, Div, DivAssign, Rem, RemAssign
6};
7
8pub trait TryNeg {
10 type Error;
12
13 type Output;
15
16 fn try_neg(self) -> Result<Self::Output, Self::Error>;
18}
19
20pub trait TryAdd<Rhs = Self> {
22 type Error;
24
25 type Output;
27
28 fn try_add(self, other: Rhs) -> Result<Self::Output, Self::Error>;
30}
31
32pub trait TrySub<Rhs = Self> {
34 type Error;
36
37 type Output;
39
40 fn try_sub(self, other: Rhs) -> Result<Self::Output, Self::Error>;
42}
43
44pub trait TryMul<Rhs = Self> {
46 type Error;
48
49 type Output;
51
52 fn try_mul(self, other: Rhs) -> Result<Self::Output, Self::Error>;
54}
55
56pub trait TryDiv<Rhs = Self> {
58 type Error;
60
61 type Output;
63
64 fn try_div(self, other: Rhs) -> Result<Self::Output, Self::Error>;
66}
67
68pub trait TryRem<Rhs = Self> {
70 type Error;
72
73 type Output;
75
76 fn try_rem(self, other: Rhs) -> Result<Self::Output, Self::Error>;
78}
79
80pub trait TryAddAssign<Rhs = Self> {
82 type Error;
84
85 fn try_add_assign(&mut self, other: Rhs) -> Result<(), Self::Error>;
87}
88
89pub trait TrySubAssign<Rhs = Self> {
91 type Error;
93
94 fn try_sub_assign(&mut self, other: Rhs) -> Result<(), Self::Error>;
96}
97
98pub trait TryMulAssign<Rhs = Self> {
100 type Error;
102
103 fn try_mul_assign(&mut self, other: Rhs) -> Result<(), Self::Error>;
105}
106
107pub trait TryDivAssign<Rhs = Self> {
109 type Error;
111
112 fn try_div_assign(&mut self, other: Rhs) -> Result<(), Self::Error>;
114}
115
116pub trait TryRemAssign<Rhs = Self> {
118 type Error;
120
121 fn try_rem_assign(&mut self, other: Rhs) -> Result<(), Self::Error>;
123}
124
125impl<T: Add<Rhs>, Rhs> TryAdd<Rhs> for T {
126 type Error = crate::Infallible;
127 type Output = <Self as Add<Rhs>>::Output;
128
129 #[inline]
130 fn try_add(self, other: Rhs) -> Result<Self::Output, Self::Error> {
131 Ok(self + other)
132 }
133}
134
135impl<T: Sub<Rhs>, Rhs> TrySub<Rhs> for T {
136 type Error = crate::Infallible;
137 type Output = <Self as Sub<Rhs>>::Output;
138
139 #[inline]
140 fn try_sub(self, other: Rhs) -> Result<Self::Output, Self::Error> {
141 Ok(self - other)
142 }
143}
144
145impl<T: Mul<Rhs>, Rhs> TryMul<Rhs> for T {
146 type Error = crate::Infallible;
147 type Output = <Self as Mul<Rhs>>::Output;
148
149 #[inline]
150 fn try_mul(self, other: Rhs) -> Result<Self::Output, Self::Error> {
151 Ok(self * other)
152 }
153}
154
155impl<T: Div<Rhs>, Rhs> TryDiv<Rhs> for T {
156 type Error = crate::Infallible;
157 type Output = <Self as Div<Rhs>>::Output;
158
159 #[inline]
160 fn try_div(self, other: Rhs) -> Result<Self::Output, Self::Error> {
161 Ok(self / other)
162 }
163}
164
165impl<T: Rem<Rhs>, Rhs> TryRem<Rhs> for T {
166 type Error = crate::Infallible;
167 type Output = <Self as Rem<Rhs>>::Output;
168
169 #[inline]
170 fn try_rem(self, other: Rhs) -> Result<Self::Output, Self::Error> {
171 Ok(self % other)
172 }
173}
174
175impl<T: AddAssign<Rhs>, Rhs> TryAddAssign<Rhs> for T {
176 type Error = crate::Infallible;
177
178 #[inline]
179 fn try_add_assign(&mut self, other: Rhs) -> Result<(), Self::Error> {
180 Ok(self.add_assign(other))
181 }
182}
183
184impl<T: SubAssign<Rhs>, Rhs> TrySubAssign<Rhs> for T {
185 type Error = crate::Infallible;
186
187 #[inline]
188 fn try_sub_assign(&mut self, other: Rhs) -> Result<(), Self::Error> {
189 Ok(self.sub_assign(other))
190 }
191}
192
193impl<T: MulAssign<Rhs>, Rhs> TryMulAssign<Rhs> for T {
194 type Error = crate::Infallible;
195
196 #[inline]
197 fn try_mul_assign(&mut self, other: Rhs) -> Result<(), Self::Error> {
198 Ok(self.mul_assign(other))
199 }
200}
201
202impl<T: DivAssign<Rhs>, Rhs> TryDivAssign<Rhs> for T {
203 type Error = crate::Infallible;
204
205 #[inline]
206 fn try_div_assign(&mut self, other: Rhs) -> Result<(), Self::Error> {
207 Ok(self.div_assign(other))
208 }
209}
210
211impl<T: RemAssign<Rhs>, Rhs> TryRemAssign<Rhs> for T {
212 type Error = crate::Infallible;
213
214 #[inline]
215 fn try_rem_assign(&mut self, other: Rhs) -> Result<(), Self::Error> {
216 Ok(self.rem_assign(other))
217 }
218}