Skip to main content

BitWriter

Struct BitWriter 

Source
pub struct BitWriter<'a, B, const MSB: bool> { /* private fields */ }
Expand description

A bit cursor that appends to a Buffer.

Unused bits in the last byte are zero.

Implementations§

Source§

impl<'a, B: Buffer, const MSB: bool> BitWriter<'a, B, MSB>

Source

pub fn new(out: &'a mut B) -> Self

A cursor at the end of out.

MSB is true to fill the top of each byte first.

Source

pub fn write(&mut self, value: u64, bits: u32) -> Result<(), Overflow>

Append the low bits bits of value.

§Errors

Overflow if a new byte does not fit. The cursor and buffer are unchanged.

Source

pub fn bit(&mut self, set: bool) -> Result<(), Overflow>

Append one bit.

§Errors

As write.

Source

pub fn patch(&mut self, at_bit: usize, bits: u32, value: u64)

Overwrite bits bits at at_bit. Those bits must already be written.

Source

pub fn position(&self) -> usize

Bits written so far.

Trait Implementations§

Source§

impl<'a, B: Debug, const MSB: bool> Debug for BitWriter<'a, B, MSB>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, B, const MSB: bool> !UnwindSafe for BitWriter<'a, B, MSB>

§

impl<'a, B, const MSB: bool> Freeze for BitWriter<'a, B, MSB>

§

impl<'a, B, const MSB: bool> RefUnwindSafe for BitWriter<'a, B, MSB>

§

impl<'a, B, const MSB: bool> Send for BitWriter<'a, B, MSB>
where &'a mut B: Send,

§

impl<'a, B, const MSB: bool> Sync for BitWriter<'a, B, MSB>
where &'a mut B: Sync,

§

impl<'a, B, const MSB: bool> Unpin for BitWriter<'a, B, MSB>

§

impl<'a, B, const MSB: bool> UnsafeUnpin for BitWriter<'a, B, MSB>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.