Coverage Report

Created: 2025-08-26 07:04

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