pub struct BitMask<T> where
T: BitStore, { /* private fields */ }
Expand description
Wrapper type indicating a one-hot encoding of a bit mask for an element.
This type is produced by BitOrder
implementations to speed up access to the
underlying memory. It ensures that masks have exactly one set bit, and can
safely be used as a mask for read/write access to memory.
Type Parameters
T
: The storage type being masked.
Implementations
sourceimpl<T> BitMask<T> where
T: BitStore,
impl<T> BitMask<T> where
T: BitStore,
sourcepub fn new(mask: T) -> Self
pub fn new(mask: T) -> Self
Produce a new bit-mask wrapper around a one-hot mask value.
BitOrder
implementations should prefer this method, but may use
::new_unchecked
if they can guarantee that the one-hot invariant is
upheld.
Parameters
mask
: The mask value to encode. This must have exactly one bit set high, and all others set low.
Returns
mask
wrapped in the BitMask
marker type.
Panics
This function unconditionally panics if mask
has zero or multiple bits
set high.
sourcepub unsafe fn new_unchecked(mask: T) -> Self
pub unsafe fn new_unchecked(mask: T) -> Self
Produce a new bit-mask wrapper around any value.
Safety
The caller must ensure that mask
has exactly one bit set. BitOrder
implementations should prefer ::new
, which always panics on failure.
Parameters
mask
: The mask value to encode. This must have exactly one bit set. Failure to uphold this requirement will introduce uncontrolled state contamination.
Returns
mask
wrapped in the BitMask
marker type.
Panics
This function panics if mask
has zero or multiple bits set, only in
debug builds. It does not inspect mask
in release builds.
Trait Implementations
sourceimpl<T: Ord> Ord for BitMask<T> where
T: BitStore,
impl<T: Ord> Ord for BitMask<T> where
T: BitStore,
sourceimpl<T: PartialOrd> PartialOrd<BitMask<T>> for BitMask<T> where
T: BitStore,
impl<T: PartialOrd> PartialOrd<BitMask<T>> for BitMask<T> where
T: BitStore,
sourcefn partial_cmp(&self, other: &BitMask<T>) -> Option<Ordering>
fn partial_cmp(&self, other: &BitMask<T>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<T: Copy> Copy for BitMask<T> where
T: BitStore,
impl<T: Eq> Eq for BitMask<T> where
T: BitStore,
impl<T> StructuralEq for BitMask<T> where
T: BitStore,
impl<T> StructuralPartialEq for BitMask<T> where
T: BitStore,
Auto Trait Implementations
impl<T> RefUnwindSafe for BitMask<T> where
T: RefUnwindSafe,
impl<T> Send for BitMask<T>
impl<T> Sync for BitMask<T>
impl<T> Unpin for BitMask<T> where
T: Unpin,
impl<T> UnwindSafe for BitMask<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more