[][src]Struct pushbits::Bits32

pub struct Bits32 { /* fields omitted */ }

32bits container where you can push and pop multiple bits as a integer.

See the crate level documentaion for more details.

Implementations

impl Bits32[src]

pub const BIT_WIDTH: u32[src]

Bit width of this container.

pub fn new(bits: u32) -> Self[src]

Create a new Bits32 container with the given bit pattern.

pub fn get(&self) -> u32[src]

Copy out the current bit pattern of this container.

Example

let mut bits = Bits32::new(0);
bits.push(5, 0b10110_u16);
bits.push_bool(true);
assert_eq!(0b10110_1, bits.get());

pub fn push<T: Into<u32>>(&mut self, num_bits: u32, value: T)[src]

Push given number of bits into the LSB of this container using the bit shift left operation.

Panics

It panics if the num_bits is greater than 31.

Examples

let mut bits = Bits32::new(0);
bits.push(8, 0b11100110_u32);
bits.push(5, 0b10001_u8);
assert_eq!(0b11100110_10001, bits.get());

pub fn push_bool(&mut self, value: bool)[src]

Push a boolean as a single bit.

Examples

let mut bits = Bits32::new(0);
bits.push_bool(true);
bits.push_bool(false);
assert_eq!(0b10, bits.get());

pub fn pop(&mut self, num_bits: u32) -> u32[src]

Pop given number of bits out from the MSB of this container using the bit shift left operation.

Panics

It panics if the num_bits is greater than 31.

Examples

let mut bits = Bits32::new(0xDEADBEEF);
assert_eq!(0xDEA, bits.pop(12));
assert_eq!(0xDBE, bits.pop(12));
assert_eq!(0xEF, bits.pop(8));

pub fn pop_bool(&mut self) -> bool[src]

Pop a single bit out as a boolean.

Examples

let mut bits = Bits32::new(0b101);
bits.push(Bits32::BIT_WIDTH - 3, 0_u32);
assert_eq!(true, bits.pop_bool());
assert_eq!(false, bits.pop_bool());
assert_eq!(true, bits.pop_bool());

Trait Implementations

impl Clone for Bits32[src]

impl Default for Bits32[src]

impl Eq for Bits32[src]

impl Ord for Bits32[src]

impl PartialEq<Bits32> for Bits32[src]

impl PartialOrd<Bits32> for Bits32[src]

impl StructuralEq for Bits32[src]

impl StructuralPartialEq for Bits32[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

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

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

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

type Owned = T

The resulting type after obtaining ownership.

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.