1#[allow(unused)]
2use core::ops::{
3 Not,
4 BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign,
5 Shl, ShlAssign, Shr, ShrAssign
6};
7
8pub trait TryNot {
10 type Error;
12
13 type Output;
15
16 fn try_not(self) -> Result<Self::Output, Self::Error>;
18}
19
20pub trait TryBitAnd<Rhs = Self> {
22 type Error;
24
25 type Output;
27
28 fn try_bitand(self, rhs: Rhs) -> Result<Self::Output, Self::Error>;
30}
31
32pub trait TryBitOr<Rhs = Self> {
34 type Error;
36
37 type Output;
39
40 fn try_bitor(self, rhs: Rhs) -> Result<Self::Output, Self::Error>;
42}
43
44pub trait TryBitXor<Rhs = Self> {
46 type Error;
48
49 type Output;
51
52 fn try_bitxor(self, rhs: Rhs) -> Result<Self::Output, Self::Error>;
54}
55
56pub trait TryShl<Rhs = Self> {
58 type Error;
60
61 type Output;
63
64 fn try_shl(self, rhs: Rhs) -> Result<Self::Output, Self::Error>;
66}
67
68pub trait TryShr<Rhs = Self> {
70 type Error;
72
73 type Output;
75
76 fn try_shr(self, rhs: Rhs) -> Result<Self::Output, Self::Error>;
78}
79
80pub trait TryBitAndAssign<Rhs = Self> {
82 type Error;
84
85 fn try_bitand_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error>;
87}
88
89pub trait TryBitOrAssign<Rhs = Self> {
91 type Error;
93
94 fn try_bitor_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error>;
96}
97
98pub trait TryBitXorAssign<Rhs = Self> {
100 type Error;
102
103 fn try_bitxor_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error>;
105}
106
107pub trait TryShlAssign<Rhs = Self> {
109 type Error;
111
112 fn try_shl_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error>;
114}
115
116pub trait TryShrAssign<Rhs = Self> {
118 type Error;
120
121 fn try_shr_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error>;
123}
124
125impl<T: Not> TryNot for T {
126 type Error = crate::Infallible;
127 type Output = <Self as Not>::Output;
128
129 #[inline]
130 fn try_not(self) -> Result<Self::Output, Self::Error> {
131 Ok(!self)
132 }
133}
134
135impl<T: BitAnd<Rhs>, Rhs> TryBitAnd<Rhs> for T {
136 type Error = crate::Infallible;
137 type Output = <Self as BitAnd<Rhs>>::Output;
138
139 #[inline]
140 fn try_bitand(self, rhs: Rhs) -> Result<Self::Output, Self::Error> {
141 Ok(self & rhs)
142 }
143}
144
145impl<T: BitOr<Rhs>, Rhs> TryBitOr<Rhs> for T {
146 type Error = crate::Infallible;
147 type Output = <Self as BitOr<Rhs>>::Output;
148
149 #[inline]
150 fn try_bitor(self, rhs: Rhs) -> Result<Self::Output, Self::Error> {
151 Ok(self | rhs)
152 }
153}
154
155impl<T: BitXor<Rhs>, Rhs> TryBitXor<Rhs> for T {
156 type Error = crate::Infallible;
157 type Output = <Self as BitXor<Rhs>>::Output;
158
159 #[inline]
160 fn try_bitxor(self, rhs: Rhs) -> Result<Self::Output, Self::Error> {
161 Ok(self ^ rhs)
162 }
163}
164
165impl<T: Shl<Rhs>, Rhs> TryShl<Rhs> for T {
166 type Error = crate::Infallible;
167 type Output = <Self as Shl<Rhs>>::Output;
168
169 #[inline]
170 fn try_shl(self, rhs: Rhs) -> Result<Self::Output, Self::Error> {
171 Ok(self << rhs)
172 }
173}
174
175impl<T: Shr<Rhs>, Rhs> TryShr<Rhs> for T {
176 type Error = crate::Infallible;
177 type Output = <Self as Shr<Rhs>>::Output;
178
179 #[inline]
180 fn try_shr(self, rhs: Rhs) -> Result<Self::Output, Self::Error> {
181 Ok(self >> rhs)
182 }
183}
184
185impl<T: BitAndAssign<Rhs>, Rhs> TryBitAndAssign<Rhs> for T {
186 type Error = crate::Infallible;
187
188 #[inline]
189 fn try_bitand_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error> {
190 Ok(self.bitand_assign(rhs))
191 }
192}
193
194impl<T: BitOrAssign<Rhs>, Rhs> TryBitOrAssign<Rhs> for T {
195 type Error = crate::Infallible;
196
197 #[inline]
198 fn try_bitor_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error> {
199 Ok(self.bitor_assign(rhs))
200 }
201}
202
203impl<T: BitXorAssign<Rhs>, Rhs> TryBitXorAssign<Rhs> for T {
204 type Error = crate::Infallible;
205
206 #[inline]
207 fn try_bitxor_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error> {
208 Ok(self.bitxor_assign(rhs))
209 }
210}
211
212impl<T: ShlAssign<Rhs>, Rhs> TryShlAssign<Rhs> for T {
213 type Error = crate::Infallible;
214
215 #[inline]
216 fn try_shl_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error> {
217 Ok(self.shl_assign(rhs))
218 }
219}
220
221impl<T: ShrAssign<Rhs>, Rhs> TryShrAssign<Rhs> for T {
222 type Error = crate::Infallible;
223
224 #[inline]
225 fn try_shr_assign(&mut self, rhs: Rhs) -> Result<(), Self::Error> {
226 Ok(self.shr_assign(rhs))
227 }
228}