[][src]Trait bitvec::fields::BitField

pub trait BitField<T> where
    T: BitStore
{ fn load<U>(&self) -> Option<U>
    where
        U: BitStore
;
fn store<U>(&mut self, value: U)
    where
        U: BitStore
; }

Permit a specific BitSlice to be used for C-style bitfield access.

Cursors that permit batched access to regions of memory are enabled to load data from a BitSlice and store data to a BitSlice with faster behavior than the default bit-by-bit traversal.

This trait transfers data between a BitSlice and an element. The trait functions always place the live bit region against the least significant bit edge of the transfer element (return value for load, argument for store).

Implementations are encouraged to preserve in-memory bit ordering, so that call sites can provide a value pattern that the user can clearly see matches what they expect for memory ordering. These methods merely move data from a fixed location in an element to a variable location in the slice.

Methods should be called as bits[start .. end].load_or_store(), where the range subslice selects up to but no more than the T::BITS width.

Required methods

fn load<U>(&self) -> Option<U> where
    U: BitStore

Load the sequence of bits from self into the least-significant bits of an element.

This can load any fundamental type which implements BitStore. Other Rust fundamental types which do not implement it must be recast appropriately by the user.

Parameters

  • &self: A read reference to some bits in memory. This slice must be trimmed to have a width no more than the U::BITS width of the type being loaded. This can be accomplished with range indexing on a larger slice.

Returns

If self has a length greater than zero, but not greater than the U element width U::BITS, then this returns an element whose least self.len() significant bits are filled with the bits of self.

If self is empty, or wider than a single element, this returns None.

fn store<U>(&mut self, value: U) where
    U: BitStore

Stores a sequence of bits from the user into the domain of self.

This can store any fundamental type which implements BitStore. Other Rust fundamental types which do not implement it must be recast appropriately by the user.

Parameters

  • &mut self: A write reference to some bits in memory. This slice must be trimmed to have a width no more than the U::BITS width of the type being stored. This can be accomplished with range indexing on a larger slice.

Behavior

If self is the empty slice, or wider than an element, then this exits without effect. Otherwise, the self.len() least significant bits of value are written into the domain of self.

Loading content...

Implementors

impl<T> BitField<T> for BitSlice<BigEndian, T> where
    T: BitStore
[src]

impl<T> BitField<T> for BitSlice<LittleEndian, T> where
    T: BitStore
[src]

Loading content...