Trait BitFieldTrait

Source
pub trait BitFieldTrait<S>{
    type Type: Copy + FromBitfield<S> + ToBitfield<S> + PartialEq + Eq;

    const NEXT_BIT: usize;

    // Required methods
    fn mask() -> S;
    fn mask_in_place() -> S;
    fn shift() -> usize;
    fn bitsize() -> usize;
    fn encode(value: Self::Type) -> S;
    fn decode(storage: S) -> Self::Type;
    fn update(value: Self::Type, original: S) -> S;
    fn is_valid(value: Self::Type) -> bool;
    fn encode_unchecked(value: Self::Type) -> S;
}
Expand description

Bitfield trait implementation, this is used to allow easy generic storage/value usage.

Without it it’s hard to get working storage/value generics.

Required Associated Constants§

Source

const NEXT_BIT: usize

Next bit after current bitfield, use this to not waste time calculating what the next bitfield position should be

Required Associated Types§

Source

type Type: Copy + FromBitfield<S> + ToBitfield<S> + PartialEq + Eq

Type we encode/decode in bitfield

Required Methods§

Source

fn mask() -> S

Mask of this bitfield

Source

fn mask_in_place() -> S

In place mask of this bitfield

Source

fn shift() -> usize

Shift of this bitfield

Source

fn bitsize() -> usize

Bitsize of this bitifield

Source

fn encode(value: Self::Type) -> S

Encodes value as bitfield

§Panics

Panics if value is not valid

Source

fn decode(storage: S) -> Self::Type

Decodes bitfield into Type

Source

fn update(value: Self::Type, original: S) -> S

Updates the value in storage original, returns updated storage

Source

fn is_valid(value: Self::Type) -> bool

Checks if value is valid to encode.

Source

fn encode_unchecked(value: Self::Type) -> S

Unchecked encode of value, all bits that can’t be encoded will be stripped down.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<S, T, const POSITION: usize, const SIZE: usize, const SIGN_EXTEND: bool> BitFieldTrait<S> for BitField<S, T, POSITION, SIZE, SIGN_EXTEND>