Struct BufBitWriter

Source
pub struct BufBitWriter<E: Endianness, WW: WordWrite, WP: WriteParams = DefaultWriteParams> { /* private fields */ }
Expand description

An implementation of BitWrite for a WordWrite.

This implementation uses a bit buffer to store bits that are not yet written. The size of the bit buffer is the size of the word used by the WordWrite, which on most platform should be usize.

The additional type parameter WP is used to select the parameters for the instantanous codes, but the casual user should be happy with the default value. See WriteParams for more details.

For additional flexibility, this structures implements std::io::Write. Note that because of coherence rules it is not possible to implement std::io::Write for a generic BitWrite.

Implementations§

Source§

impl<E: Endianness, WW: WordWrite, WP: WriteParams> BufBitWriter<E, WW, WP>
where BufBitWriter<E, WW, WP>: BitWrite<E>,

Source

pub fn new(backend: WW) -> Self

Create a new BufBitWriter around a WordWrite.

§Example
use dsi_bitstream::prelude::*;
let buffer = Vec::<usize>::new();
let word_writer = MemWordWriterVec::new(buffer);
let mut buf_bit_writer = <BufBitWriter<BE, _>>::new(word_writer);
Source

pub fn into_inner(self) -> Result<WW, <Self as BitWrite<E>>::Error>

Return the backend, consuming this writer after flushing it.

Trait Implementations§

Source§

impl<WW: WordWrite, WP: WriteParams> BitWrite<BigEndian> for BufBitWriter<BE, WW, WP>
where u64: CastableInto<WW::Word>,

Source§

type Error = <WW as WordWrite>::Error

Source§

fn flush(&mut self) -> Result<usize, Self::Error>

Flush the buffer, consuming the bit stream. Read more
Source§

fn write_bits( &mut self, value: u64, n_bits: usize, ) -> Result<usize, Self::Error>

Write the lowest n bits of value to the stream and return the number of bits written, that is, n. Read more
Source§

fn write_unary(&mut self, value: u64) -> Result<usize, Self::Error>

Write value as a unary code to the stream and return the number of bits written, that is, value plus one.
Source§

fn copy_from<F: Endianness, R: BitRead<F>>( &mut self, bit_read: &mut R, n: u64, ) -> Result<(), CopyError<R::Error, Self::Error>>

Source§

impl<WW: WordWrite, WP: WriteParams> BitWrite<LittleEndian> for BufBitWriter<LE, WW, WP>
where u64: CastableInto<WW::Word>,

Source§

type Error = <WW as WordWrite>::Error

Source§

fn flush(&mut self) -> Result<usize, Self::Error>

Flush the buffer, consuming the bit stream. Read more
Source§

fn write_bits( &mut self, value: u64, n_bits: usize, ) -> Result<usize, Self::Error>

Write the lowest n bits of value to the stream and return the number of bits written, that is, n. Read more
Source§

fn write_unary(&mut self, value: u64) -> Result<usize, Self::Error>

Write value as a unary code to the stream and return the number of bits written, that is, value plus one.
Source§

fn copy_from<F: Endianness, R: BitRead<F>>( &mut self, bit_read: &mut R, n: u64, ) -> Result<(), CopyError<R::Error, Self::Error>>

Source§

impl<E: Endianness, WW, WP: WriteParams> CopyType for BufBitWriter<E, WW, WP>

Source§

impl<E: Debug + Endianness, WW: Debug + WordWrite, WP: Debug + WriteParams> Debug for BufBitWriter<E, WW, WP>
where WW::Word: Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<WR: WordWrite, DC: WriteParams> DeltaWrite<BigEndian> for BufBitWriter<BigEndian, WR, DC>
where u64: CastableInto<WR::Word>,

Source§

fn write_delta(&mut self, value: u64) -> Result<usize, Self::Error>

Source§

impl<WR: WordWrite, DC: WriteParams> DeltaWrite<LittleEndian> for BufBitWriter<LittleEndian, WR, DC>
where u64: CastableInto<WR::Word>,

Source§

fn write_delta(&mut self, value: u64) -> Result<usize, Self::Error>

Source§

impl<E: Endianness, WW: WordWrite, WP: WriteParams> Drop for BufBitWriter<E, WW, WP>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<WR: WordWrite> GammaWrite<BigEndian> for BufBitWriter<BigEndian, WR, DefaultWriteParams>
where u64: CastableInto<WR::Word>,

Source§

fn write_gamma(&mut self, value: u64) -> Result<usize, Self::Error>

Source§

impl<WR: WordWrite> GammaWrite<LittleEndian> for BufBitWriter<LittleEndian, WR, DefaultWriteParams>
where u64: CastableInto<WR::Word>,

Source§

fn write_gamma(&mut self, value: u64) -> Result<usize, Self::Error>

Source§

impl<E: Endianness, WW, WP: WriteParams> MemDbgImpl for BufBitWriter<E, WW, WP>

Source§

fn _mem_dbg_rec_on( &self, _memdbg_writer: &mut impl Write, _memdbg_total_size: usize, _memdbg_max_depth: usize, _memdbg_prefix: &mut String, _memdbg_is_last: bool, _memdbg_flags: DbgFlags, ) -> Result

Source§

fn _mem_dbg_depth_on( &self, writer: &mut impl Write, total_size: usize, max_depth: usize, prefix: &mut String, field_name: Option<&str>, is_last: bool, padded_size: usize, flags: DbgFlags, ) -> Result<(), Error>

Source§

impl<E: Endianness, WW, WP: WriteParams> MemSize for BufBitWriter<E, WW, WP>

Source§

fn mem_size(&self, _memsize_flags: SizeFlags) -> usize

Returns the (recursively computed) overall memory size of the structure in bytes.
Source§

impl<WW: WordWrite, WP: WriteParams> Write for BufBitWriter<BE, WW, WP>
where u64: CastableInto<WW::Word>,

Source§

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

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

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

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. 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
Source§

impl<WW: WordWrite, WP: WriteParams> Write for BufBitWriter<LE, WW, WP>
where u64: CastableInto<WW::Word>,

Source§

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

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

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

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. 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
Source§

impl<WR: WordWrite, DC: WriteParams> ZetaWrite<BigEndian> for BufBitWriter<BigEndian, WR, DC>
where u64: CastableInto<WR::Word>,

Source§

fn write_zeta(&mut self, value: u64, k: usize) -> Result<usize, Self::Error>

Source§

fn write_zeta3(&mut self, value: u64) -> Result<usize, Self::Error>

Source§

impl<WR: WordWrite, DC: WriteParams> ZetaWrite<LittleEndian> for BufBitWriter<LittleEndian, WR, DC>
where u64: CastableInto<WR::Word>,

Source§

fn write_zeta(&mut self, value: u64, k: usize) -> Result<usize, Self::Error>

Source§

fn write_zeta3(&mut self, value: u64) -> Result<usize, Self::Error>

Auto Trait Implementations§

§

impl<E, WW, WP> Freeze for BufBitWriter<E, WW, WP>
where WW: Freeze, <WW as WordWrite>::Word: Freeze,

§

impl<E, WW, WP> RefUnwindSafe for BufBitWriter<E, WW, WP>

§

impl<E, WW, WP> Send for BufBitWriter<E, WW, WP>
where WW: Send, WP: Send,

§

impl<E, WW, WP> Sync for BufBitWriter<E, WW, WP>
where WW: Sync, WP: Sync,

§

impl<E, WW, WP> Unpin for BufBitWriter<E, WW, WP>
where WW: Unpin, <WW as WordWrite>::Word: Unpin, E: Unpin, WP: Unpin,

§

impl<E, WW, WP> UnwindSafe for BufBitWriter<E, WW, WP>
where WW: UnwindSafe, <WW as WordWrite>::Word: UnwindSafe, E: UnwindSafe, WP: 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> CastableFrom<T> for T

Source§

fn cast_from(value: T) -> T

Call Self as W
Source§

impl<T, U> CastableInto<U> for T
where U: CastableFrom<T>,

Source§

fn cast(self) -> U

Call W::cast_from(self)
Source§

impl<B> DeltaWriteParam<BigEndian> for B

Source§

fn write_delta_param<const USE_DELTA_TABLE: bool, const USE_GAMMA_TABLE: bool>( &mut self, n: u64, ) -> Result<usize, <B as BitWrite<BigEndian>>::Error>

Source§

impl<B> DeltaWriteParam<LittleEndian> for B

Source§

fn write_delta_param<const USE_DELTA_TABLE: bool, const USE_GAMMA_TABLE: bool>( &mut self, n: u64, ) -> Result<usize, <B as BitWrite<LittleEndian>>::Error>

Source§

impl<T> DowncastableFrom<T> for T

Source§

fn downcast_from(value: T) -> T

Truncate the current UnsignedInt to a possibly smaller size
Source§

impl<T, U> DowncastableInto<U> for T
where U: DowncastableFrom<T>,

Source§

fn downcast(self) -> U

Call W::downcast_from(self)
Source§

impl<E, B> ExpGolombWrite<E> for B
where E: Endianness, B: BitWrite<E> + GammaWrite<E>,

Source§

fn write_exp_golomb(&mut self, n: u64, k: usize) -> Result<usize, Self::Error>

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<B> GammaWriteParam<BigEndian> for B
where B: BitWrite<BigEndian>,

Source§

fn write_gamma_param<const USE_TABLE: bool>( &mut self, n: u64, ) -> Result<usize, <B as BitWrite<BigEndian>>::Error>

Source§

impl<B> GammaWriteParam<LittleEndian> for B

Source§

fn write_gamma_param<const USE_TABLE: bool>( &mut self, n: u64, ) -> Result<usize, <B as BitWrite<LittleEndian>>::Error>

Source§

impl<E, B> GolombWrite<E> for B
where E: Endianness, B: BitWrite<E>,

Source§

fn write_golomb(&mut self, n: u64, b: u64) -> Result<usize, Self::Error>

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> MemDbg for T
where T: MemDbgImpl,

Source§

fn mem_dbg(&self, flags: DbgFlags) -> Result<(), Error>

Writes to stderr debug infos about the structure memory usage, expanding all levels of nested structures.
Source§

fn mem_dbg_on( &self, writer: &mut impl Write, flags: DbgFlags, ) -> Result<(), Error>

Writes to a core::fmt::Write debug infos about the structure memory usage, expanding all levels of nested structures.
Source§

fn mem_dbg_depth(&self, max_depth: usize, flags: DbgFlags) -> Result<(), Error>

Writes to stderr debug infos about the structure memory usage as mem_dbg, but expanding only up to max_depth levels of nested structures.
Source§

fn mem_dbg_depth_on( &self, writer: &mut impl Write, max_depth: usize, flags: DbgFlags, ) -> Result<(), Error>

Writes to a core::fmt::Write debug infos about the structure memory usage as mem_dbg_on, but expanding only up to max_depth levels of nested structures.
Source§

impl<E, B> MinimalBinaryWrite<E> for B
where E: Endianness, B: BitWrite<E>,

Source§

fn write_minimal_binary( &mut self, n: u64, max: u64, ) -> Result<usize, Self::Error>

Source§

impl<E, B> OmegaWrite<E> for B
where E: Endianness, B: BitWrite<E>,

Source§

fn write_omega(&mut self, n: u64) -> Result<usize, Self::Error>

Source§

impl<E, B> PiWrite<E> for B
where E: Endianness, B: BitWrite<E> + RiceWrite<E> + ?Sized,

Source§

fn write_pi(&mut self, n: u64, k: usize) -> Result<usize, Self::Error>

Source§

impl<E, B> RiceWrite<E> for B
where E: Endianness, B: BitWrite<E>,

Source§

fn write_rice(&mut self, n: u64, log2_b: usize) -> Result<usize, Self::Error>

Source§

impl<T> Splat<T> for T

Source§

fn splat(value: T) -> T

Source§

impl<T> To<T> for T

Source§

fn to(self) -> T

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<T> UpcastableFrom<T> for T

Source§

fn upcast_from(value: T) -> T

Extend the current UnsignedInt to a possibly bigger size.
Source§

impl<T, U> UpcastableInto<U> for T
where U: UpcastableFrom<T>,

Source§

fn upcast(self) -> U

Call W::upcast_from(self)
Source§

impl<E, B> VByteBeWrite<E> for B
where E: Endianness, B: BitWrite<E>,

Source§

fn write_vbyte_be( &mut self, value: u64, ) -> Result<usize, <B as BitWrite<E>>::Error>

Source§

impl<E, B> VByteLeWrite<E> for B
where E: Endianness, B: BitWrite<E>,

Source§

fn write_vbyte_le( &mut self, value: u64, ) -> Result<usize, <B as BitWrite<E>>::Error>

Source§

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

Source§

fn vzip(self) -> V

Source§

impl<B> ZetaWriteParam<BigEndian> for B
where B: BitWrite<BigEndian>,

Source§

fn write_zeta_param<const USE_TABLE: bool>( &mut self, n: u64, k: usize, ) -> Result<usize, <B as BitWrite<BigEndian>>::Error>

Source§

fn write_zeta3_param<const USE_TABLE: bool>( &mut self, n: u64, ) -> Result<usize, <B as BitWrite<BigEndian>>::Error>

Source§

impl<B> ZetaWriteParam<LittleEndian> for B

Source§

fn write_zeta_param<const USE_TABLE: bool>( &mut self, n: u64, k: usize, ) -> Result<usize, <B as BitWrite<LittleEndian>>::Error>

Source§

fn write_zeta3_param<const USE_TABLE: bool>( &mut self, n: u64, ) -> Result<usize, <B as BitWrite<LittleEndian>>::Error>

Source§

impl<E, B> CodesWrite<E> for B