Coverage Report

Created: 2025-06-22 07:07

/rust/registry/src/index.crates.io-6f17d22bba15001f/bitvec-1.0.1/src/slice/specialization.rs
Line
Count
Source (jump to first uncovered line)
1
#![doc = include_str!("../../doc/slice/specialization.md")]
2
3
use funty::Integral;
4
5
use super::BitSlice;
6
use crate::{
7
  devel as dvl,
8
  mem,
9
  order::BitOrder,
10
  store::BitStore,
11
};
12
13
mod lsb0;
14
mod msb0;
15
16
/// Processor width, used for chunking.
17
const WORD_BITS: usize = mem::bits_of::<usize>();
18
19
/// Tests whether the masked portion of an integer has a `0` bit in it.
20
0
fn has_zero<T>(val: T, mask: T) -> bool
21
0
where T: Integral {
22
0
  val | !mask != !T::ZERO
23
0
}
24
25
/// Tests whether the masked portion of an integer has a `1` bit in it.
26
0
fn has_one<T>(val: T, mask: T) -> bool
27
0
where T: Integral {
28
0
  val & mask != T::ZERO
29
0
}
30
31
impl<T, O> BitSlice<T, O>
32
where
33
  T: BitStore,
34
  O: BitOrder,
35
{
36
  /// Forces the storage type parameter to be its accessor type.
37
  ///
38
  /// Functions must use this when working with maybe-overlapping regions
39
  /// within a single bit-slice, as the accessor is always tolerant of
40
  /// aliasing.
41
  #[inline]
42
0
  fn as_accessor(&mut self) -> &BitSlice<T::Access, O> {
43
0
    unsafe { &*(self as *const Self as *const BitSlice<T::Access, O>) }
44
0
  }
45
46
  /// Attempts to change a bit-slice reference to caller-supplied type
47
  /// parameters.
48
  ///
49
  /// If `<T, O>` is identical to `<T2, O2>`, this returns `Some` with the
50
  /// bit-slice reference unchanged in value but changed in type. If the types
51
  /// differ, it returns `None`. This is useful for creating statically-known
52
  /// bit-slice types within generic contexts.
53
139k
  pub(crate) fn coerce<T2, O2>(&self) -> Option<&BitSlice<T2, O2>>
54
139k
  where
55
139k
    T2: BitStore,
56
139k
    O2: BitOrder,
57
139k
  {
58
139k
    if dvl::match_types::<T, O, T2, O2>() {
59
69.7k
      Some(unsafe { &*(self as *const Self as *const BitSlice<T2, O2>) })
60
    }
61
    else {
62
69.7k
      None
63
    }
64
139k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0>>::coerce::<u8, bitvec::order::Msb0>
Line
Count
Source
53
69.7k
  pub(crate) fn coerce<T2, O2>(&self) -> Option<&BitSlice<T2, O2>>
54
69.7k
  where
55
69.7k
    T2: BitStore,
56
69.7k
    O2: BitOrder,
57
69.7k
  {
58
69.7k
    if dvl::match_types::<T, O, T2, O2>() {
59
69.7k
      Some(unsafe { &*(self as *const Self as *const BitSlice<T2, O2>) })
60
    }
61
    else {
62
0
      None
63
    }
64
69.7k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0>>::coerce::<u8, bitvec::order::Lsb0>
Line
Count
Source
53
69.7k
  pub(crate) fn coerce<T2, O2>(&self) -> Option<&BitSlice<T2, O2>>
54
69.7k
  where
55
69.7k
    T2: BitStore,
56
69.7k
    O2: BitOrder,
57
69.7k
  {
58
69.7k
    if dvl::match_types::<T, O, T2, O2>() {
59
0
      Some(unsafe { &*(self as *const Self as *const BitSlice<T2, O2>) })
60
    }
61
    else {
62
69.7k
      None
63
    }
64
69.7k
  }
Unexecuted instantiation: <bitvec::slice::BitSlice<_, _>>::coerce::<_, _>
65
66
  /// See [`.coerce()`].
67
  ///
68
  /// [`.coerce()`]: Self::coerce
69
139k
  pub(crate) fn coerce_mut<T2, O2>(&mut self) -> Option<&mut BitSlice<T2, O2>>
70
139k
  where
71
139k
    T2: BitStore,
72
139k
    O2: BitOrder,
73
139k
  {
74
139k
    if dvl::match_types::<T, O, T2, O2>() {
75
69.7k
      Some(unsafe { &mut *(self as *mut Self as *mut BitSlice<T2, O2>) })
76
    }
77
    else {
78
69.7k
      None
79
    }
80
139k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0>>::coerce_mut::<u8, bitvec::order::Msb0>
Line
Count
Source
69
69.7k
  pub(crate) fn coerce_mut<T2, O2>(&mut self) -> Option<&mut BitSlice<T2, O2>>
70
69.7k
  where
71
69.7k
    T2: BitStore,
72
69.7k
    O2: BitOrder,
73
69.7k
  {
74
69.7k
    if dvl::match_types::<T, O, T2, O2>() {
75
69.7k
      Some(unsafe { &mut *(self as *mut Self as *mut BitSlice<T2, O2>) })
76
    }
77
    else {
78
0
      None
79
    }
80
69.7k
  }
<bitvec::slice::BitSlice<u8, bitvec::order::Msb0>>::coerce_mut::<u8, bitvec::order::Lsb0>
Line
Count
Source
69
69.7k
  pub(crate) fn coerce_mut<T2, O2>(&mut self) -> Option<&mut BitSlice<T2, O2>>
70
69.7k
  where
71
69.7k
    T2: BitStore,
72
69.7k
    O2: BitOrder,
73
69.7k
  {
74
69.7k
    if dvl::match_types::<T, O, T2, O2>() {
75
0
      Some(unsafe { &mut *(self as *mut Self as *mut BitSlice<T2, O2>) })
76
    }
77
    else {
78
69.7k
      None
79
    }
80
69.7k
  }
Unexecuted instantiation: <bitvec::slice::BitSlice<_, _>>::coerce_mut::<_, _>
81
}