Skip to main content

Unpacker

Struct Unpacker 

Source
pub struct Unpacker<B> { /* private fields */ }
Expand description

Sequentially unpacks values from a buffer.

Each unpack call extracts the lower SIZE bits of the buffer and shifts the remaining bits down, so values are extracted in reverse order of how they were packed.

Most callers will not interact with Unpacker directly — the #[packable] macro generates code that uses it.

§Example

use bitcram::Unpacker;

let mut unpacker = Unpacker::<u32>::new(0b1011);
assert_eq!(unpacker.raw_unpack(1), 0b1);
assert_eq!(unpacker.raw_unpack(3), 0b101);

Implementations§

Source§

impl<B: Buffer> Unpacker<B>

Source

pub fn new(buffer: B) -> Self

Creates a new unpacker over buffer.

Source

pub fn unpack<P: Packable<B>>(&mut self) -> P

Extracts a value from the buffer using its Packable implementation.

Source

pub fn raw_unpack(&mut self, size: u32) -> B

Extracts the lower size bits of the buffer and advances past them.

size must satisfy size < B::BITS. Reading exactly B::BITS of data requires multiple calls each smaller than B::BITS.

Source

pub fn into_inner(self) -> B

Consumes the unpacker and returns the remaining buffer state.

Trait Implementations§

Source§

impl<B: Debug> Debug for Unpacker<B>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<B> Freeze for Unpacker<B>
where B: Freeze,

§

impl<B> RefUnwindSafe for Unpacker<B>
where B: RefUnwindSafe,

§

impl<B> Send for Unpacker<B>
where B: Send,

§

impl<B> Sync for Unpacker<B>
where B: Sync,

§

impl<B> Unpin for Unpacker<B>
where B: Unpin,

§

impl<B> UnsafeUnpin for Unpacker<B>
where B: UnsafeUnpin,

§

impl<B> UnwindSafe for Unpacker<B>
where B: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.