Struct BitWriter

Source
pub struct BitWriter<W: Write> { /* private fields */ }
Expand description

Bitwise writer formed by wrapping a bytewise io::Write. Bits are written in big-endian order. Bytes are filled with zeroes for padding.

Implementations§

Source§

impl<W: Write> BitWriter<W>

Source

pub fn new(w: W) -> BitWriter<W>

Create a bitwise writer from a bytewise one. Equivalent to using From.

Source

pub fn write_bit(&mut self, b: bool) -> Result<()>

Write a single bit.

Source

pub fn flush_all(&mut self) -> Result<()>

Write out all cached bits. This may write up to two bytes and flushes the underlying io::Write.

Source

pub fn n_total_written(&self) -> usize

Return total number of written bits.

Source

pub fn write_bits_be(&mut self, n: u64, len: usize) -> Result<usize>

Write up to 64 bits in big-endian order. The first len many least significant bits from n are written.

Returns the number of written bits.

Trait Implementations§

Source§

impl<W: Write> From<W> for BitWriter<W>

Source§

fn from(w: W) -> Self

Converts to this type from the input type.
Source§

impl<W: Write> Write for BitWriter<W>

Source§

fn flush(&mut self) -> Result<()>

Does not write out cached bits (i.e. bits written since the last byte boundary). To do this you must call BitWriter::flush_all().

Source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

Writes a buffer into this writer, returning how many bytes were written. Read more
1.36.0 · Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
Source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<W> UnwindSafe for BitWriter<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 = 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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<W> WriteBytesExt for W
where W: Write + ?Sized,

Source§

fn write_u8(&mut self, n: u8) -> Result<(), Error>

Writes an unsigned 8 bit integer to the underlying writer. Read more
Source§

fn write_i8(&mut self, n: i8) -> Result<(), Error>

Writes a signed 8 bit integer to the underlying writer. Read more
Source§

fn write_u16<T>(&mut self, n: u16) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 16 bit integer to the underlying writer. Read more
Source§

fn write_i16<T>(&mut self, n: i16) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 16 bit integer to the underlying writer. Read more
Source§

fn write_u24<T>(&mut self, n: u32) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 24 bit integer to the underlying writer. Read more
Source§

fn write_i24<T>(&mut self, n: i32) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 24 bit integer to the underlying writer. Read more
Source§

fn write_u32<T>(&mut self, n: u32) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 32 bit integer to the underlying writer. Read more
Source§

fn write_i32<T>(&mut self, n: i32) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 32 bit integer to the underlying writer. Read more
Source§

fn write_u48<T>(&mut self, n: u64) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 48 bit integer to the underlying writer. Read more
Source§

fn write_i48<T>(&mut self, n: i64) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 48 bit integer to the underlying writer. Read more
Source§

fn write_u64<T>(&mut self, n: u64) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 64 bit integer to the underlying writer. Read more
Source§

fn write_i64<T>(&mut self, n: i64) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 64 bit integer to the underlying writer. Read more
Source§

fn write_u128<T>(&mut self, n: u128) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 128 bit integer to the underlying writer.
Source§

fn write_i128<T>(&mut self, n: i128) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 128 bit integer to the underlying writer.
Source§

fn write_uint<T>(&mut self, n: u64, nbytes: usize) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned n-bytes integer to the underlying writer. Read more
Source§

fn write_int<T>(&mut self, n: i64, nbytes: usize) -> Result<(), Error>
where T: ByteOrder,

Writes a signed n-bytes integer to the underlying writer. Read more
Source§

fn write_uint128<T>(&mut self, n: u128, nbytes: usize) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned n-bytes integer to the underlying writer. Read more
Source§

fn write_int128<T>(&mut self, n: i128, nbytes: usize) -> Result<(), Error>
where T: ByteOrder,

Writes a signed n-bytes integer to the underlying writer. Read more
Source§

fn write_f32<T>(&mut self, n: f32) -> Result<(), Error>
where T: ByteOrder,

Writes a IEEE754 single-precision (4 bytes) floating point number to the underlying writer. Read more
Source§

fn write_f64<T>(&mut self, n: f64) -> Result<(), Error>
where T: ByteOrder,

Writes a IEEE754 double-precision (8 bytes) floating point number to the underlying writer. Read more
Source§

impl<W> WriteExt for W
where W: Write + ?Sized,

Source§

fn emit_u64(&mut self, v: u64) -> Result<(), Error>

Outputs a 64-bit unsigned integer.
Source§

fn emit_u32(&mut self, v: u32) -> Result<(), Error>

Outputs a 32-bit unsigned integer.
Source§

fn emit_u16(&mut self, v: u16) -> Result<(), Error>

Outputs a 16-bit unsigned integer.
Source§

fn emit_i64(&mut self, v: i64) -> Result<(), Error>

Outputs a 64-bit signed integer.
Source§

fn emit_i32(&mut self, v: i32) -> Result<(), Error>

Outputs a 32-bit signed integer.
Source§

fn emit_i16(&mut self, v: i16) -> Result<(), Error>

Outputs a 16-bit signed integer.
Source§

fn emit_i8(&mut self, v: i8) -> Result<(), Error>

Outputs an 8-bit signed integer.
Source§

fn emit_u8(&mut self, v: u8) -> Result<(), Error>

Outputs an 8-bit unsigned integer.
Source§

fn emit_bool(&mut self, v: bool) -> Result<(), Error>

Outputs a boolean.
Source§

fn emit_slice(&mut self, v: &[u8]) -> Result<usize, Error>

Outputs a byte slice.
Source§

fn emit_varint(&mut self, v: u64) -> Result<usize, Error>

Outputs a variable sized integer.