[][src]Struct ari::BitField

#[repr(C)]
pub struct BitField<TStorage, TAlignment> where
    TStorage: AsRef<[u8]> + AsMut<[u8]>, 
{ /* fields omitted */ }

a bitfield.

this is c ffi compatible, which means for example a [u8; 4] bitfield consumes 4 bytes of space. just like a u32-based c-style bitfield.

examples.


let mut x: BitField<[u8; 4], u32> = BitField::new([0u8; 4]);

assert_eq!(x.value(), &[0, 0, 0, 0]);

x.set(0, true);
x.set(4, true);
x.set(8, true);
x.set(16, true);
x.set_value(20, 3, 7u64);

assert_eq!(x.get(0), true);
assert_eq!(x.get(4), true);
assert_eq!(x.get(8), true);
assert_eq!(x.get(16), true);
assert_eq!(x.get_value(20, 3): u64, 7);

assert_eq!(x.value(), &[17, 1, 113, 0]);

Methods

impl<TStorage, TAlignment> BitField<TStorage, TAlignment> where
    TStorage: AsRef<[u8]> + AsMut<[u8]>, 
[src]

pub fn new(storage: TStorage) -> Self[src]

creates a new bitfield with the specified value.

examples.


let mut x: BitField<[u8; 4], u32> = BitField::new([0u8; 4]);

assert_eq!(x.value(), &[0, 0, 0, 0]);

pub fn get(&self, index: usize) -> bool[src]

retrieves the bit at index.

examples.


let mut x: BitField<[u8; 4], u32> = BitField::new([0u8; 4]);

assert_eq!(x.get(0), false);

pub fn set(&mut self, index: usize, value: bool)[src]

places value at the specified bit index.

examples.


let mut x: BitField<[u8; 4], u32> = BitField::new([0u8; 4]);

x.set(0, true);

assert_eq!(x.get(0), true);

pub fn get_value<T>(&self, offset: usize, width: usize) -> T where
    T: From<u64>, 
[src]

retrieves the value at the specified bit range [offset..offset + width].

examples.


let mut x: BitField<[u8; 4], u32> = BitField::new([0u8; 4]);

x.set_value(0, 5, 0xfffffu64);
assert_eq!(x.get_value::<u64>(0, 5), 31);

pub fn set_value<T>(&mut self, offset: usize, width: usize, value: T) where
    T: Into<u64>, 
[src]

places value at the specified bit range [offset..offset + width].

value is truncated if it exceeds the maximum representable value defined by (offset, width).

examples.

simple example.


let mut x: BitField<[u8; 4], u32> = BitField::new([0u8; 4]);

x.set_value(0, 5, 0xfffffu64);

assert_eq!(x.get_value(0, 5): u64, 31);

4 bit value truncated to 2 bits.


let mut x: BitField<[u8; 4], u32> = BitField::new([0u8; 4]);

x.set_value(0, 2, 0b1111u64);

assert_eq!(x.get_value(0, 4): u64, 0b11);

pub fn value(&self) -> &TStorage[src]

returns the raw value of this bitfield.

examples.


let mut x: BitField<[u8; 4], u32> = BitField::new([0u8; 4]);

x.set(0, true);
x.set(4, true);
x.set(8, true);
x.set(16, true);
x.set_value(20, 3, 9u64);

assert_eq!(x.value(), &[17, 1, 17, 0]);

Trait Implementations

impl<TStorage: Clone, TAlignment: Clone> Clone for BitField<TStorage, TAlignment> where
    TStorage: AsRef<[u8]> + AsMut<[u8]>, 
[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<TStorage: Ord, TAlignment: Ord> Ord for BitField<TStorage, TAlignment> where
    TStorage: AsRef<[u8]> + AsMut<[u8]>, 
[src]

fn max(self, other: Self) -> Self1.21.0[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self1.21.0[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

🔬 This is a nightly-only experimental API. (clamp)

Restrict a value to a certain interval. Read more

impl<TStorage: Default, TAlignment: Default> Default for BitField<TStorage, TAlignment> where
    TStorage: AsRef<[u8]> + AsMut<[u8]>, 
[src]

impl<TStorage: PartialOrd, TAlignment: PartialOrd> PartialOrd<BitField<TStorage, TAlignment>> for BitField<TStorage, TAlignment> where
    TStorage: AsRef<[u8]> + AsMut<[u8]>, 
[src]

impl<TStorage: PartialEq, TAlignment: PartialEq> PartialEq<BitField<TStorage, TAlignment>> for BitField<TStorage, TAlignment> where
    TStorage: AsRef<[u8]> + AsMut<[u8]>, 
[src]

impl<TStorage: Copy, TAlignment: Copy> Copy for BitField<TStorage, TAlignment> where
    TStorage: AsRef<[u8]> + AsMut<[u8]>, 
[src]

impl<TStorage: Eq, TAlignment: Eq> Eq for BitField<TStorage, TAlignment> where
    TStorage: AsRef<[u8]> + AsMut<[u8]>, 
[src]

impl<TStorage: Debug, TAlignment: Debug> Debug for BitField<TStorage, TAlignment> where
    TStorage: AsRef<[u8]> + AsMut<[u8]>, 
[src]

impl<TStorage: Hash, TAlignment: Hash> Hash for BitField<TStorage, TAlignment> where
    TStorage: AsRef<[u8]> + AsMut<[u8]>, 
[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given [Hasher]. Read more

Auto Trait Implementations

impl<TStorage, TAlignment> Sync for BitField<TStorage, TAlignment> where
    TAlignment: Sync,
    TStorage: Sync

impl<TStorage, TAlignment> Send for BitField<TStorage, TAlignment> where
    TAlignment: Send,
    TStorage: Send

impl<TStorage, TAlignment> Unpin for BitField<TStorage, TAlignment> where
    TAlignment: Unpin,
    TStorage: Unpin

impl<TStorage, TAlignment> RefUnwindSafe for BitField<TStorage, TAlignment> where
    TAlignment: RefUnwindSafe,
    TStorage: RefUnwindSafe

impl<TStorage, TAlignment> UnwindSafe for BitField<TStorage, TAlignment> where
    TAlignment: UnwindSafe,
    TStorage: UnwindSafe

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,