Skip to content

Commit

Permalink
fix(bitfield): make Packing work with typed specs (#295)
Browse files Browse the repository at this point in the history
This adds generics to the `Packing{N}` struct's `set_all`, `unset_all`,
and similar methods, so that they can be used to flip all the bits in a
typed packing spec.
  • Loading branch information
hawkw committed Aug 10, 2022
1 parent 532ee98 commit 7b86e81
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions bitfield/src/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,36 +830,36 @@ macro_rules! make_packers {
/// # Panics
///
/// If `value` contains bits outside the range specified by `packer`.
pub fn pack<T: FromBits<$Bits>>(self, value: T, packer: &$Pack<T>) -> Self {
pub fn pack<T: FromBits<$Bits>, F>(self, value: T, packer: &$Pack<T, F>) -> Self {
Self(packer.pack(value, self.0))
}

/// Set _all_ bits in the range specified by `packer` to 1 in `self`.
#[inline]
pub const fn set_all(self, packer: &$Pack) -> Self {
pub const fn set_all<T, F>(self, packer: &$Pack<T, F>) -> Self {
Self(packer.set_all(self.0))
}

/// Set _all_ bits in the range specified by `packer` to 0 in
/// `self`.
#[inline]
pub const fn unset_all(self, packer: &$Pack) -> Self {
pub const fn unset_all<T, F>(self, packer: &$Pack<T, F>) -> Self {
Self(packer.unset_all(self.0))
}


/// Returns `true` if **any** bits specified by `packer` are set
/// in `self`.
#[inline]
pub const fn contains_any(self, packer: &$Pack) -> bool {
pub const fn contains_any<T, F>(self, packer: &$Pack<T, F>) -> bool {
packer.contained_in_any(self.0)
}


/// Returns `true` if **any** bits specified by `packer` are set
/// in `self`.
#[inline]
pub const fn contains_all(self, packer: &$Pack) -> bool {
pub const fn contains_all<T, F>(self, packer: &$Pack<T, F>) -> bool {
packer.contained_in_all(self.0)
}

Expand Down

0 comments on commit 7b86e81

Please sign in to comment.