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>,
impl<E: Endianness, WW: WordWrite, WP: WriteParams> BufBitWriter<E, WW, WP>where
BufBitWriter<E, WW, WP>: BitWrite<E>,
Sourcepub fn new(backend: WW) -> Self
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);
Sourcepub fn into_inner(self) -> Result<WW, <Self as BitWrite<E>>::Error>
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>
impl<WW: WordWrite, WP: WriteParams> BitWrite<BigEndian> for BufBitWriter<BE, WW, WP>
type Error = <WW as WordWrite>::Error
Source§fn flush(&mut self) -> Result<usize, Self::Error>
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>
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 moreSource§fn write_unary(&mut self, value: u64) -> Result<usize, Self::Error>
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.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>
impl<WW: WordWrite, WP: WriteParams> BitWrite<LittleEndian> for BufBitWriter<LE, WW, WP>
type Error = <WW as WordWrite>::Error
Source§fn flush(&mut self) -> Result<usize, Self::Error>
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>
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 moreSource§fn write_unary(&mut self, value: u64) -> Result<usize, Self::Error>
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.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>
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>
impl<E: Debug + Endianness, WW: Debug + WordWrite, WP: Debug + WriteParams> Debug for BufBitWriter<E, WW, WP>
Source§impl<WR: WordWrite, DC: WriteParams> DeltaWrite<BigEndian> for BufBitWriter<BigEndian, WR, DC>
impl<WR: WordWrite, DC: WriteParams> DeltaWrite<BigEndian> for BufBitWriter<BigEndian, WR, DC>
Source§impl<WR: WordWrite, DC: WriteParams> DeltaWrite<LittleEndian> for BufBitWriter<LittleEndian, WR, DC>
impl<WR: WordWrite, DC: WriteParams> DeltaWrite<LittleEndian> for BufBitWriter<LittleEndian, WR, DC>
Source§impl<E: Endianness, WW: WordWrite, WP: WriteParams> Drop for BufBitWriter<E, WW, WP>
impl<E: Endianness, WW: WordWrite, WP: WriteParams> Drop for BufBitWriter<E, WW, WP>
Source§impl<WR: WordWrite> GammaWrite<BigEndian> for BufBitWriter<BigEndian, WR, DefaultWriteParams>
impl<WR: WordWrite> GammaWrite<BigEndian> for BufBitWriter<BigEndian, WR, DefaultWriteParams>
Source§impl<WR: WordWrite> GammaWrite<LittleEndian> for BufBitWriter<LittleEndian, WR, DefaultWriteParams>
impl<WR: WordWrite> GammaWrite<LittleEndian> for BufBitWriter<LittleEndian, WR, DefaultWriteParams>
Source§impl<E: Endianness, WW, WP: WriteParams> MemDbgImpl for BufBitWriter<E, WW, WP>where
WW: MemDbgImpl + WordWrite,
WW::Word: MemDbgImpl,
usize: MemDbgImpl,
PhantomData<(E, WP)>: MemDbgImpl,
impl<E: Endianness, WW, WP: WriteParams> MemDbgImpl for BufBitWriter<E, WW, WP>where
WW: MemDbgImpl + WordWrite,
WW::Word: MemDbgImpl,
usize: MemDbgImpl,
PhantomData<(E, WP)>: MemDbgImpl,
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
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>
impl<E: Endianness, WW, WP: WriteParams> MemSize for BufBitWriter<E, WW, WP>
Source§impl<WW: WordWrite, WP: WriteParams> Write for BufBitWriter<BE, WW, WP>
impl<WW: WordWrite, WP: WriteParams> Write for BufBitWriter<BE, WW, WP>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
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<()>
fn flush(&mut self) -> Result<()>
Flushes this output stream, ensuring that all intermediately buffered
contents reach their destination. Read more
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
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>
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
Source§impl<WW: WordWrite, WP: WriteParams> Write for BufBitWriter<LE, WW, WP>
impl<WW: WordWrite, WP: WriteParams> Write for BufBitWriter<LE, WW, WP>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
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<()>
fn flush(&mut self) -> Result<()>
Flushes this output stream, ensuring that all intermediately buffered
contents reach their destination. Read more
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
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>
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
Source§impl<WR: WordWrite, DC: WriteParams> ZetaWrite<BigEndian> for BufBitWriter<BigEndian, WR, DC>
impl<WR: WordWrite, DC: WriteParams> ZetaWrite<BigEndian> for BufBitWriter<BigEndian, WR, DC>
Source§impl<WR: WordWrite, DC: WriteParams> ZetaWrite<LittleEndian> for BufBitWriter<LittleEndian, WR, DC>
impl<WR: WordWrite, DC: WriteParams> ZetaWrite<LittleEndian> for BufBitWriter<LittleEndian, WR, DC>
Auto Trait Implementations§
impl<E, WW, WP> Freeze for BufBitWriter<E, WW, WP>
impl<E, WW, WP> RefUnwindSafe for BufBitWriter<E, WW, WP>where
WW: RefUnwindSafe,
<WW as WordWrite>::Word: RefUnwindSafe,
E: RefUnwindSafe,
WP: RefUnwindSafe,
impl<E, WW, WP> Send for BufBitWriter<E, WW, WP>
impl<E, WW, WP> Sync for BufBitWriter<E, WW, WP>
impl<E, WW, WP> Unpin for BufBitWriter<E, WW, WP>
impl<E, WW, WP> UnwindSafe for BufBitWriter<E, WW, WP>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T, U> CastableInto<U> for Twhere
U: CastableFrom<T>,
impl<T, U> CastableInto<U> for Twhere
U: CastableFrom<T>,
Source§impl<B> DeltaWriteParam<BigEndian> for Bwhere
B: GammaWriteParam<BigEndian>,
impl<B> DeltaWriteParam<BigEndian> for Bwhere
B: GammaWriteParam<BigEndian>,
Source§impl<B> DeltaWriteParam<LittleEndian> for Bwhere
B: GammaWriteParam<LittleEndian>,
impl<B> DeltaWriteParam<LittleEndian> for Bwhere
B: GammaWriteParam<LittleEndian>,
Source§impl<T> DowncastableFrom<T> for T
impl<T> DowncastableFrom<T> for T
Source§fn downcast_from(value: T) -> T
fn downcast_from(value: T) -> T
Truncate the current UnsignedInt to a possibly smaller size
Source§impl<T, U> DowncastableInto<U> for Twhere
U: DowncastableFrom<T>,
impl<T, U> DowncastableInto<U> for Twhere
U: DowncastableFrom<T>,
Source§impl<E, B> ExpGolombWrite<E> for B
impl<E, B> ExpGolombWrite<E> for B
Source§impl<B> GammaWriteParam<BigEndian> for B
impl<B> GammaWriteParam<BigEndian> for B
Source§impl<B> GammaWriteParam<LittleEndian> for Bwhere
B: BitWrite<LittleEndian>,
impl<B> GammaWriteParam<LittleEndian> for Bwhere
B: BitWrite<LittleEndian>,
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 Bwhere
E: Endianness,
B: BitWrite<E>,
impl<E, B> GolombWrite<E> for Bwhere
E: Endianness,
B: BitWrite<E>,
Source§impl<T> MemDbg for Twhere
T: MemDbgImpl,
impl<T> MemDbg for Twhere
T: MemDbgImpl,
Source§fn mem_dbg(&self, flags: DbgFlags) -> Result<(), Error>
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>
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>
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>
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 Bwhere
E: Endianness,
B: BitWrite<E>,
impl<E, B> MinimalBinaryWrite<E> for Bwhere
E: Endianness,
B: BitWrite<E>,
Source§impl<E, B> OmegaWrite<E> for Bwhere
E: Endianness,
B: BitWrite<E>,
impl<E, B> OmegaWrite<E> for Bwhere
E: Endianness,
B: BitWrite<E>,
Source§impl<E, B> RiceWrite<E> for Bwhere
E: Endianness,
B: BitWrite<E>,
impl<E, B> RiceWrite<E> for Bwhere
E: Endianness,
B: BitWrite<E>,
Source§impl<T> UpcastableFrom<T> for T
impl<T> UpcastableFrom<T> for T
Source§fn upcast_from(value: T) -> T
fn upcast_from(value: T) -> T
Extend the current UnsignedInt to a possibly bigger size.