Skip to main content

BitOutputStream

Struct BitOutputStream 

Source
pub struct BitOutputStream<W> { /* private fields */ }
Expand description

Big-endian bit writer backed by a byte stream.

Implementations§

Source§

impl<W: Write> BitOutputStream<W>

Source

pub fn new(output: W) -> Self

Constructs a bit output stream writing big-endian bits to output.

Source

pub fn write_bit(&mut self, bit: u8) -> Result<(), ArithError>

Writes a single bit (0 or 1) to the stream.

§Errors

Returns ArithError::InvalidBit if bit > 1, or ArithError::Io on write failure.

Source

pub fn finish_padding(&mut self) -> Result<(), ArithError>

Zero-pads any partial byte up to the next byte boundary and flushes the underlying writer.

§Errors

Returns ArithError::Io if writing or flushing fails.

Source

pub fn flush(&mut self) -> Result<(), ArithError>

Flushes the underlying writer without padding the current partial byte.

§Errors

Returns ArithError::Io if flushing fails.

Source

pub fn get_ref(&self) -> &W

Returns a shared reference to the underlying writer.

Source

pub fn get_mut(&mut self) -> &mut W

Returns a mutable reference to the underlying writer.

Source

pub fn into_inner(self) -> Result<W, ArithError>

Finishes padding, flushes, and returns the underlying writer.

§Errors

Returns ArithError::Io if padding or flushing fails.

Source§

impl<W: Write + Seek> BitOutputStream<W>

Source

pub fn state(&mut self) -> Result<BitOutputState, ArithError>

Flushes buffered full bytes and captures the exact output stream state for checkpointing.

§Errors

Returns ArithError::Io if flushing or querying stream position fails.

Source

pub fn restore_state(&mut self, state: BitOutputState) -> Result<(), ArithError>

Restores a previously captured BitOutputState by seeking to state.file_position.

When resuming onto an existing file on disk, prefer Self::restore_file_state so any bytes written after the checkpoint are truncated.

§Errors

Returns ArithError::InvalidStreamState if num_bits_filled >= 8, or ArithError::Io on flush/seek errors.

Source§

impl BitOutputStream<File>

Source

pub fn restore_file_state( &mut self, state: BitOutputState, ) -> Result<(), ArithError>

Restores a BitOutputState on a file, truncating any bytes beyond file_position.

§Errors

Returns ArithError::InvalidStreamState or ArithError::Io.

Source§

impl BitOutputStream<BufWriter<File>>

Source

pub fn restore_file_state( &mut self, state: BitOutputState, ) -> Result<(), ArithError>

Restores a BitOutputState on a buffered file, truncating any bytes beyond file_position.

§Errors

Returns ArithError::InvalidStreamState or ArithError::Io.

Trait Implementations§

Source§

impl<W: Debug> Debug for BitOutputStream<W>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<W> Freeze for BitOutputStream<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for BitOutputStream<W>
where W: RefUnwindSafe,

§

impl<W> Send for BitOutputStream<W>
where W: Send,

§

impl<W> Sync for BitOutputStream<W>
where W: Sync,

§

impl<W> Unpin for BitOutputStream<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for BitOutputStream<W>
where W: UnsafeUnpin,

§

impl<W> UnwindSafe for BitOutputStream<W>
where W: 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 = !

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.