Coverage Report

Created: 2025-11-24 06:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/bitvec-1.0.1/src/vec/traits.rs
Line
Count
Source
1
//! General trait implementations for bit-vectors.
2
3
use alloc::{
4
  borrow::{
5
    Cow,
6
    ToOwned,
7
  },
8
  vec::Vec,
9
};
10
use core::{
11
  borrow::{
12
    Borrow,
13
    BorrowMut,
14
  },
15
  cmp,
16
  convert::TryFrom,
17
  fmt::{
18
    self,
19
    Debug,
20
    Display,
21
    Formatter,
22
  },
23
  hash::{
24
    Hash,
25
    Hasher,
26
  },
27
  marker::Unpin,
28
};
29
30
use super::BitVec;
31
use crate::{
32
  array::BitArray,
33
  boxed::BitBox,
34
  order::BitOrder,
35
  slice::BitSlice,
36
  store::BitStore,
37
  view::BitViewSized,
38
};
39
40
#[cfg(not(tarpaulin_include))]
41
impl<T, O> Borrow<BitSlice<T, O>> for BitVec<T, O>
42
where
43
  T: BitStore,
44
  O: BitOrder,
45
{
46
  #[inline]
47
0
  fn borrow(&self) -> &BitSlice<T, O> {
48
0
    self.as_bitslice()
49
0
  }
50
}
51
52
#[cfg(not(tarpaulin_include))]
53
impl<T, O> BorrowMut<BitSlice<T, O>> for BitVec<T, O>
54
where
55
  T: BitStore,
56
  O: BitOrder,
57
{
58
  #[inline]
59
0
  fn borrow_mut(&mut self) -> &mut BitSlice<T, O> {
60
0
    self.as_mut_bitslice()
61
0
  }
62
}
63
64
#[cfg(not(tarpaulin_include))]
65
impl<T, O> Clone for BitVec<T, O>
66
where
67
  T: BitStore,
68
  O: BitOrder,
69
{
70
  #[inline]
71
0
  fn clone(&self) -> Self {
72
0
    Self::from_bitslice(self.as_bitslice())
73
0
  }
74
}
75
76
impl<T, O> Eq for BitVec<T, O>
77
where
78
  T: BitStore,
79
  O: BitOrder,
80
{
81
}
82
83
#[cfg(not(tarpaulin_include))]
84
impl<T, O> Ord for BitVec<T, O>
85
where
86
  T: BitStore,
87
  O: BitOrder,
88
{
89
  #[inline]
90
0
  fn cmp(&self, other: &Self) -> cmp::Ordering {
91
0
    self.as_bitslice().cmp(other.as_bitslice())
92
0
  }
93
}
94
95
#[cfg(not(tarpaulin_include))]
96
impl<T1, T2, O1, O2> PartialEq<BitVec<T2, O2>> for BitSlice<T1, O1>
97
where
98
  T1: BitStore,
99
  T2: BitStore,
100
  O1: BitOrder,
101
  O2: BitOrder,
102
{
103
  #[inline]
104
0
  fn eq(&self, other: &BitVec<T2, O2>) -> bool {
105
0
    self == other.as_bitslice()
106
0
  }
107
}
108
109
#[cfg(not(tarpaulin_include))]
110
impl<T1, T2, O1, O2> PartialEq<BitVec<T2, O2>> for &BitSlice<T1, O1>
111
where
112
  T1: BitStore,
113
  T2: BitStore,
114
  O1: BitOrder,
115
  O2: BitOrder,
116
{
117
  #[inline]
118
0
  fn eq(&self, other: &BitVec<T2, O2>) -> bool {
119
0
    *self == other.as_bitslice()
120
0
  }
121
}
122
123
#[cfg(not(tarpaulin_include))]
124
impl<T1, T2, O1, O2> PartialEq<BitVec<T2, O2>> for &mut BitSlice<T1, O1>
125
where
126
  T1: BitStore,
127
  T2: BitStore,
128
  O1: BitOrder,
129
  O2: BitOrder,
130
{
131
  #[inline]
132
0
  fn eq(&self, other: &BitVec<T2, O2>) -> bool {
133
0
    **self == other.as_bitslice()
134
0
  }
135
}
136
137
#[cfg(not(tarpaulin_include))]
138
impl<T, O, Rhs> PartialEq<Rhs> for BitVec<T, O>
139
where
140
  T: BitStore,
141
  O: BitOrder,
142
  Rhs: ?Sized + PartialEq<BitSlice<T, O>>,
143
{
144
  #[inline]
145
0
  fn eq(&self, other: &Rhs) -> bool {
146
0
    other == self.as_bitslice()
147
0
  }
148
}
149
150
#[cfg(not(tarpaulin_include))]
151
impl<T1, T2, O1, O2> PartialOrd<BitVec<T2, O2>> for BitSlice<T1, O1>
152
where
153
  T1: BitStore,
154
  T2: BitStore,
155
  O1: BitOrder,
156
  O2: BitOrder,
157
{
158
  #[inline]
159
0
  fn partial_cmp(&self, other: &BitVec<T2, O2>) -> Option<cmp::Ordering> {
160
0
    self.partial_cmp(other.as_bitslice())
161
0
  }
162
}
163
164
#[cfg(not(tarpaulin_include))]
165
impl<'a, T1, T2, O1, O2> PartialOrd<BitVec<T2, O2>> for &'a BitSlice<T1, O1>
166
where
167
  T1: BitStore,
168
  T2: BitStore,
169
  O1: BitOrder,
170
  O2: BitOrder,
171
{
172
  #[inline]
173
0
  fn partial_cmp(&self, other: &BitVec<T2, O2>) -> Option<cmp::Ordering> {
174
0
    self.partial_cmp(other.as_bitslice())
175
0
  }
176
}
177
178
#[cfg(not(tarpaulin_include))]
179
impl<'a, T1, T2, O1, O2> PartialOrd<BitVec<T2, O2>> for &'a mut BitSlice<T1, O1>
180
where
181
  T1: BitStore,
182
  T2: BitStore,
183
  O1: BitOrder,
184
  O2: BitOrder,
185
{
186
  #[inline]
187
0
  fn partial_cmp(&self, other: &BitVec<T2, O2>) -> Option<cmp::Ordering> {
188
0
    self.partial_cmp(other.as_bitslice())
189
0
  }
190
}
191
192
#[cfg(not(tarpaulin_include))]
193
impl<T, O, Rhs> PartialOrd<Rhs> for BitVec<T, O>
194
where
195
  T: BitStore,
196
  O: BitOrder,
197
  Rhs: ?Sized + PartialOrd<BitSlice<T, O>>,
198
{
199
  #[inline]
200
0
  fn partial_cmp(&self, other: &Rhs) -> Option<cmp::Ordering> {
201
0
    other.partial_cmp(self.as_bitslice())
202
0
  }
203
}
204
205
#[cfg(not(tarpaulin_include))]
206
impl<T, O> AsRef<BitSlice<T, O>> for BitVec<T, O>
207
where
208
  T: BitStore,
209
  O: BitOrder,
210
{
211
  #[inline]
212
0
  fn as_ref(&self) -> &BitSlice<T, O> {
213
0
    self.as_bitslice()
214
0
  }
215
}
216
217
#[cfg(not(tarpaulin_include))]
218
impl<T, O> AsMut<BitSlice<T, O>> for BitVec<T, O>
219
where
220
  T: BitStore,
221
  O: BitOrder,
222
{
223
  #[inline]
224
0
  fn as_mut(&mut self) -> &mut BitSlice<T, O> {
225
0
    self.as_mut_bitslice()
226
0
  }
227
}
228
229
#[cfg(not(tarpaulin_include))]
230
impl<T, O> AsRef<BitVec<T, O>> for BitVec<T, O>
231
where
232
  T: BitStore,
233
  O: BitOrder,
234
{
235
  #[inline]
236
0
  fn as_ref(&self) -> &Self {
237
0
    self
238
0
  }
239
}
240
241
#[cfg(not(tarpaulin_include))]
242
impl<T, O> AsMut<BitVec<T, O>> for BitVec<T, O>
243
where
244
  T: BitStore,
245
  O: BitOrder,
246
{
247
  #[inline]
248
0
  fn as_mut(&mut self) -> &mut Self {
249
0
    self
250
0
  }
251
}
252
253
#[cfg(not(tarpaulin_include))]
254
impl<T, O> From<&'_ BitSlice<T, O>> for BitVec<T, O>
255
where
256
  T: BitStore,
257
  O: BitOrder,
258
{
259
  #[inline]
260
0
  fn from(slice: &BitSlice<T, O>) -> Self {
261
0
    Self::from_bitslice(slice)
262
0
  }
263
}
264
265
#[cfg(not(tarpaulin_include))]
266
impl<T, O> From<&'_ mut BitSlice<T, O>> for BitVec<T, O>
267
where
268
  T: BitStore,
269
  O: BitOrder,
270
{
271
  #[inline]
272
0
  fn from(slice: &mut BitSlice<T, O>) -> Self {
273
0
    Self::from_bitslice(slice)
274
0
  }
275
}
276
277
#[cfg(not(tarpaulin_include))]
278
impl<A, O> From<BitArray<A, O>> for BitVec<A::Store, O>
279
where
280
  O: BitOrder,
281
  A: BitViewSized,
282
{
283
  #[inline]
284
0
  fn from(array: BitArray<A, O>) -> Self {
285
0
    array.as_bitslice().to_owned()
286
0
  }
287
}
288
289
#[cfg(not(tarpaulin_include))]
290
impl<T, O> From<BitBox<T, O>> for BitVec<T, O>
291
where
292
  T: BitStore,
293
  O: BitOrder,
294
{
295
  #[inline]
296
0
  fn from(boxed: BitBox<T, O>) -> Self {
297
0
    boxed.into_bitvec()
298
0
  }
299
}
300
301
#[cfg(not(tarpaulin_include))]
302
impl<T, O> From<BitVec<T, O>> for Vec<T>
303
where
304
  T: BitStore,
305
  O: BitOrder,
306
{
307
  #[inline]
308
0
  fn from(bv: BitVec<T, O>) -> Self {
309
0
    bv.into_vec()
310
0
  }
311
}
312
313
#[cfg(not(tarpaulin_include))]
314
impl<'a, T, O> From<Cow<'a, BitSlice<T, O>>> for BitVec<T, O>
315
where
316
  O: BitOrder,
317
  T: 'a + BitStore,
318
{
319
  #[inline]
320
0
  fn from(cow: Cow<'a, BitSlice<T, O>>) -> Self {
321
0
    cow.into_owned()
322
0
  }
323
}
324
325
#[cfg(not(tarpaulin_include))]
326
impl<T, O> TryFrom<Vec<T>> for BitVec<T, O>
327
where
328
  T: BitStore,
329
  O: BitOrder,
330
{
331
  type Error = Vec<T>;
332
333
  #[inline]
334
0
  fn try_from(vec: Vec<T>) -> Result<Self, Self::Error> {
335
0
    Self::try_from_vec(vec)
336
0
  }
337
}
338
339
#[cfg(not(tarpaulin_include))]
340
impl<T, O> Default for BitVec<T, O>
341
where
342
  T: BitStore,
343
  O: BitOrder,
344
{
345
  #[inline]
346
0
  fn default() -> Self {
347
0
    Self::new()
348
0
  }
349
}
350
351
impl<T, O> Debug for BitVec<T, O>
352
where
353
  T: BitStore,
354
  O: BitOrder,
355
{
356
  #[inline]
357
0
  fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
358
0
    self.as_bitspan().render(fmt, "Vec", &[(
359
0
      "capacity",
360
0
      &self.capacity() as &dyn Debug,
361
0
    )])?;
362
0
    fmt.write_str(" ")?;
363
0
    Display::fmt(self, fmt)
364
0
  }
365
}
366
367
easy_fmt! {
368
  impl Binary
369
  impl Display
370
  impl LowerHex
371
  impl Octal
372
  impl Pointer
373
  impl UpperHex
374
  for BitVec
375
}
376
377
#[cfg(not(tarpaulin_include))]
378
impl<T, O> Hash for BitVec<T, O>
379
where
380
  T: BitStore,
381
  O: BitOrder,
382
{
383
  #[inline]
384
0
  fn hash<H>(&self, state: &mut H)
385
0
  where H: Hasher {
386
0
    self.as_bitslice().hash(state)
387
0
  }
388
}
389
390
unsafe impl<T, O> Send for BitVec<T, O>
391
where
392
  T: BitStore,
393
  O: BitOrder,
394
{
395
}
396
397
unsafe impl<T, O> Sync for BitVec<T, O>
398
where
399
  T: BitStore,
400
  O: BitOrder,
401
{
402
}
403
404
impl<T, O> Unpin for BitVec<T, O>
405
where
406
  T: BitStore,
407
  O: BitOrder,
408
{
409
}