/rust/registry/src/index.crates.io-6f17d22bba15001f/bitvec-1.0.1/src/boxed/ops.rs
Line | Count | Source (jump to first uncovered line) |
1 | | //! Operator trait implementations for boxed bit-slices. |
2 | | |
3 | | use core::{ |
4 | | mem::ManuallyDrop, |
5 | | ops::{ |
6 | | BitAnd, |
7 | | BitAndAssign, |
8 | | BitOr, |
9 | | BitOrAssign, |
10 | | BitXor, |
11 | | BitXorAssign, |
12 | | Deref, |
13 | | DerefMut, |
14 | | Index, |
15 | | IndexMut, |
16 | | Not, |
17 | | }, |
18 | | }; |
19 | | |
20 | | use super::BitBox; |
21 | | use crate::{ |
22 | | order::BitOrder, |
23 | | slice::BitSlice, |
24 | | store::BitStore, |
25 | | }; |
26 | | |
27 | | #[cfg(not(tarpaulin_include))] |
28 | | impl<T, O> BitAndAssign<BitBox<T, O>> for BitSlice<T, O> |
29 | | where |
30 | | T: BitStore, |
31 | | O: BitOrder, |
32 | | { |
33 | | #[inline] |
34 | 0 | fn bitand_assign(&mut self, rhs: BitBox<T, O>) { |
35 | 0 | *self &= rhs.as_bitslice() |
36 | 0 | } |
37 | | } |
38 | | |
39 | | #[cfg(not(tarpaulin_include))] |
40 | | impl<T, O> BitAndAssign<&BitBox<T, O>> for BitSlice<T, O> |
41 | | where |
42 | | T: BitStore, |
43 | | O: BitOrder, |
44 | | { |
45 | | #[inline] |
46 | 0 | fn bitand_assign(&mut self, rhs: &BitBox<T, O>) { |
47 | 0 | *self &= rhs.as_bitslice() |
48 | 0 | } |
49 | | } |
50 | | |
51 | | impl<T, O, Rhs> BitAnd<Rhs> for BitBox<T, O> |
52 | | where |
53 | | T: BitStore, |
54 | | O: BitOrder, |
55 | | BitSlice<T, O>: BitAndAssign<Rhs>, |
56 | | { |
57 | | type Output = Self; |
58 | | |
59 | | #[inline] |
60 | 0 | fn bitand(mut self, rhs: Rhs) -> Self::Output { |
61 | 0 | self &= rhs; |
62 | 0 | self |
63 | 0 | } |
64 | | } |
65 | | |
66 | | impl<T, O, Rhs> BitAndAssign<Rhs> for BitBox<T, O> |
67 | | where |
68 | | T: BitStore, |
69 | | O: BitOrder, |
70 | | BitSlice<T, O>: BitAndAssign<Rhs>, |
71 | | { |
72 | | #[inline] |
73 | 0 | fn bitand_assign(&mut self, rhs: Rhs) { |
74 | 0 | *self.as_mut_bitslice() &= rhs; |
75 | 0 | } |
76 | | } |
77 | | |
78 | | #[cfg(not(tarpaulin_include))] |
79 | | impl<T, O> BitOrAssign<BitBox<T, O>> for BitSlice<T, O> |
80 | | where |
81 | | T: BitStore, |
82 | | O: BitOrder, |
83 | | { |
84 | | #[inline] |
85 | 0 | fn bitor_assign(&mut self, rhs: BitBox<T, O>) { |
86 | 0 | *self |= rhs.as_bitslice() |
87 | 0 | } |
88 | | } |
89 | | |
90 | | #[cfg(not(tarpaulin_include))] |
91 | | impl<T, O> BitOrAssign<&BitBox<T, O>> for BitSlice<T, O> |
92 | | where |
93 | | T: BitStore, |
94 | | O: BitOrder, |
95 | | { |
96 | | #[inline] |
97 | 0 | fn bitor_assign(&mut self, rhs: &BitBox<T, O>) { |
98 | 0 | *self |= rhs.as_bitslice() |
99 | 0 | } |
100 | | } |
101 | | |
102 | | impl<T, O, Rhs> BitOr<Rhs> for BitBox<T, O> |
103 | | where |
104 | | T: BitStore, |
105 | | O: BitOrder, |
106 | | BitSlice<T, O>: BitOrAssign<Rhs>, |
107 | | { |
108 | | type Output = Self; |
109 | | |
110 | | #[inline] |
111 | 0 | fn bitor(mut self, rhs: Rhs) -> Self::Output { |
112 | 0 | self |= rhs; |
113 | 0 | self |
114 | 0 | } |
115 | | } |
116 | | |
117 | | impl<T, O, Rhs> BitOrAssign<Rhs> for BitBox<T, O> |
118 | | where |
119 | | T: BitStore, |
120 | | O: BitOrder, |
121 | | BitSlice<T, O>: BitOrAssign<Rhs>, |
122 | | { |
123 | | #[inline] |
124 | 0 | fn bitor_assign(&mut self, rhs: Rhs) { |
125 | 0 | *self.as_mut_bitslice() |= rhs; |
126 | 0 | } |
127 | | } |
128 | | |
129 | | #[cfg(not(tarpaulin_include))] |
130 | | impl<T, O> BitXorAssign<BitBox<T, O>> for BitSlice<T, O> |
131 | | where |
132 | | T: BitStore, |
133 | | O: BitOrder, |
134 | | { |
135 | | #[inline] |
136 | 0 | fn bitxor_assign(&mut self, rhs: BitBox<T, O>) { |
137 | 0 | *self ^= rhs.as_bitslice() |
138 | 0 | } |
139 | | } |
140 | | |
141 | | #[cfg(not(tarpaulin_include))] |
142 | | impl<T, O> BitXorAssign<&BitBox<T, O>> for BitSlice<T, O> |
143 | | where |
144 | | T: BitStore, |
145 | | O: BitOrder, |
146 | | { |
147 | | #[inline] |
148 | 0 | fn bitxor_assign(&mut self, rhs: &BitBox<T, O>) { |
149 | 0 | *self ^= rhs.as_bitslice() |
150 | 0 | } |
151 | | } |
152 | | |
153 | | impl<T, O, Rhs> BitXor<Rhs> for BitBox<T, O> |
154 | | where |
155 | | T: BitStore, |
156 | | O: BitOrder, |
157 | | BitSlice<T, O>: BitXorAssign<Rhs>, |
158 | | { |
159 | | type Output = Self; |
160 | | |
161 | | #[inline] |
162 | 0 | fn bitxor(mut self, rhs: Rhs) -> Self::Output { |
163 | 0 | self ^= rhs; |
164 | 0 | self |
165 | 0 | } |
166 | | } |
167 | | |
168 | | impl<T, O, Rhs> BitXorAssign<Rhs> for BitBox<T, O> |
169 | | where |
170 | | T: BitStore, |
171 | | O: BitOrder, |
172 | | BitSlice<T, O>: BitXorAssign<Rhs>, |
173 | | { |
174 | | #[inline] |
175 | 0 | fn bitxor_assign(&mut self, rhs: Rhs) { |
176 | 0 | *self.as_mut_bitslice() ^= rhs; |
177 | 0 | } |
178 | | } |
179 | | |
180 | | impl<T, O> Deref for BitBox<T, O> |
181 | | where |
182 | | T: BitStore, |
183 | | O: BitOrder, |
184 | | { |
185 | | type Target = BitSlice<T, O>; |
186 | | |
187 | | #[inline] |
188 | 0 | fn deref(&self) -> &Self::Target { |
189 | 0 | self.as_bitslice() |
190 | 0 | } |
191 | | } |
192 | | |
193 | | impl<T, O> DerefMut for BitBox<T, O> |
194 | | where |
195 | | T: BitStore, |
196 | | O: BitOrder, |
197 | | { |
198 | | #[inline] |
199 | 0 | fn deref_mut(&mut self) -> &mut Self::Target { |
200 | 0 | self.as_mut_bitslice() |
201 | 0 | } |
202 | | } |
203 | | |
204 | | impl<T, O> Drop for BitBox<T, O> |
205 | | where |
206 | | T: BitStore, |
207 | | O: BitOrder, |
208 | | { |
209 | | #[inline] |
210 | 0 | fn drop(&mut self) { |
211 | 0 | self.with_box(|b| unsafe { ManuallyDrop::drop(b) }) |
212 | 0 | } |
213 | | } |
214 | | |
215 | | #[cfg(not(tarpaulin_include))] |
216 | | impl<T, O, Idx> Index<Idx> for BitBox<T, O> |
217 | | where |
218 | | T: BitStore, |
219 | | O: BitOrder, |
220 | | BitSlice<T, O>: Index<Idx>, |
221 | | { |
222 | | type Output = <BitSlice<T, O> as Index<Idx>>::Output; |
223 | | |
224 | | #[inline] |
225 | 0 | fn index(&self, index: Idx) -> &Self::Output { |
226 | 0 | &self.as_bitslice()[index] |
227 | 0 | } |
228 | | } |
229 | | |
230 | | #[cfg(not(tarpaulin_include))] |
231 | | impl<T, O, Idx> IndexMut<Idx> for BitBox<T, O> |
232 | | where |
233 | | T: BitStore, |
234 | | O: BitOrder, |
235 | | BitSlice<T, O>: IndexMut<Idx>, |
236 | | { |
237 | | #[inline] |
238 | 0 | fn index_mut(&mut self, index: Idx) -> &mut Self::Output { |
239 | 0 | &mut self.as_mut_bitslice()[index] |
240 | 0 | } |
241 | | } |
242 | | |
243 | | impl<T, O> Not for BitBox<T, O> |
244 | | where |
245 | | T: BitStore, |
246 | | O: BitOrder, |
247 | | { |
248 | | type Output = Self; |
249 | | |
250 | | #[inline] |
251 | 0 | fn not(mut self) -> Self::Output { |
252 | 0 | for elem in self.as_raw_mut_slice().iter_mut() { |
253 | 0 | elem.store_value(!elem.load_value()); |
254 | 0 | } |
255 | 0 | self |
256 | 0 | } |
257 | | } |