pub struct BitField<S, T, const POSITION: usize, const SIZE: usize, const SIGN_EXTEND: bool>(/* private fields */);
Expand description
A bitfield descriptor type. Define an alias to this structure in order to use it properly.
§Parameters
S
: Storage container for bitfield, must be larger or equal toSIZE
.T
: Type to store in a bitfield, must implementToBitfield
andFromBitfield
traits, this allows us to also encode booleans and enums easily in bitfield.POSITION
: position of bitfield in storage container, must not be out of bounds.SIZE
: Size of the bitfield, note that if T is u32 and we set size to 16 then only 16 bits of the 32-bit value will be stored.SIGN_EXTEND
: Whether or not to do sign-extension on decode operation.
§Example usage
use easy_bitfield::*;
// simple boolean bitfield at position 0
pub type MyBitfield = BitField<usize, bool, 0, 1, false>;
// simple 17-bit bitfield that is encoded/decoded from u32, located at second bit
pub type OtherBitfield = BitField<usize, u32, { MyBitfield::NEXT_BIT }, 17, false>;
Trait Implementations§
Source§impl<S, T, const POSITION: usize, const SIZE: usize, const SIGN_EXTEND: bool> BitFieldTrait<S> for BitField<S, T, POSITION, SIZE, SIGN_EXTEND>where
S: ToPrimitive + FromPrimitive + One + PrimInt,
T: FromBitfield<S> + ToBitfield<S> + PartialEq + Eq + Copy,
impl<S, T, const POSITION: usize, const SIZE: usize, const SIGN_EXTEND: bool> BitFieldTrait<S> for BitField<S, T, POSITION, SIZE, SIGN_EXTEND>where
S: ToPrimitive + FromPrimitive + One + PrimInt,
T: FromBitfield<S> + ToBitfield<S> + PartialEq + Eq + Copy,
Source§const NEXT_BIT: usize
const NEXT_BIT: usize
Next bit after current bitfield, use this to not waste time calculating
what the next bitfield position should be
Source§fn mask_in_place() -> S
fn mask_in_place() -> S
In place mask of this bitfield
Source§fn update(value: T, original: S) -> S
fn update(value: T, original: S) -> S
Updates the value in storage
original
, returns updated storageSource§fn encode_unchecked(value: T) -> S
fn encode_unchecked(value: T) -> S
Unchecked encode of
value
, all bits that can’t be encoded will be stripped down.Auto Trait Implementations§
impl<S, T, const POSITION: usize, const SIZE: usize, const SIGN_EXTEND: bool> Freeze for BitField<S, T, POSITION, SIZE, SIGN_EXTEND>
impl<S, T, const POSITION: usize, const SIZE: usize, const SIGN_EXTEND: bool> RefUnwindSafe for BitField<S, T, POSITION, SIZE, SIGN_EXTEND>where
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<S, T, const POSITION: usize, const SIZE: usize, const SIGN_EXTEND: bool> Send for BitField<S, T, POSITION, SIZE, SIGN_EXTEND>
impl<S, T, const POSITION: usize, const SIZE: usize, const SIGN_EXTEND: bool> Sync for BitField<S, T, POSITION, SIZE, SIGN_EXTEND>
impl<S, T, const POSITION: usize, const SIZE: usize, const SIGN_EXTEND: bool> Unpin for BitField<S, T, POSITION, SIZE, SIGN_EXTEND>
impl<S, T, const POSITION: usize, const SIZE: usize, const SIGN_EXTEND: bool> UnwindSafe for BitField<S, T, POSITION, SIZE, SIGN_EXTEND>where
S: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more