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 platforms should be usize.
The additional type parameter WP is used to select the parameters for the
instantaneous codes, but the casual user should be happy with the default
value. See WriteParams for more details.
The convenience functions from_path and from_file (requiring the
std feature) create a BufBitWriter around a buffered file writer.
For additional flexibility, when the std feature is enabled, this
structure implements std::io::Write. Note that because of coherence
rules it is not possible to implement std::io::Write for a generic
BitWrite.
§Panics on drop
The Drop implementation flushes the buffer, which requires writing to
the backend. If the backend write fails, the drop will panic. To handle
errors gracefully, call flush or into_inner
explicitly before dropping.
Implementations§
Source§impl<E: Endianness, WW: WordWrite, WP: WriteParams> BufBitWriter<E, WW, WP>
impl<E: Endianness, WW: WordWrite, WP: WriteParams> BufBitWriter<E, WW, WP>
Sourcepub const fn new(backend: WW) -> Self
pub const fn new(backend: WW) -> Self
Creates a new BufBitWriter around a WordWrite.
§Examples
#[cfg(not(feature = "std"))]
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§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 into_inner(self) -> Result<WW, <Self as BitWrite<E>>::Error>
pub fn into_inner(self) -> Result<WW, <Self as BitWrite<E>>::Error>
Returns 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>
Source§fn write_bits(
&mut self,
value: u64,
num_bits: usize,
) -> Result<usize, Self::Error>
fn write_bits( &mut self, value: u64, num_bits: usize, ) -> Result<usize, Self::Error>
num_bits bits of value to the stream and
returns the number of bits written, that is, num_bits. Read moreSource§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>
Source§fn write_bits(
&mut self,
value: u64,
num_bits: usize,
) -> Result<usize, Self::Error>
fn write_bits( &mut self, value: u64, num_bits: usize, ) -> Result<usize, Self::Error>
num_bits bits of value to the stream and
returns the number of bits written, that is, num_bits. Read moreSource§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, WP: WriteParams> DeltaWrite<BigEndian> for BufBitWriter<BigEndian, WR, WP>
impl<WR: WordWrite, WP: WriteParams> DeltaWrite<BigEndian> for BufBitWriter<BigEndian, WR, WP>
Source§impl<WR: WordWrite, WP: WriteParams> DeltaWrite<LittleEndian> for BufBitWriter<LittleEndian, WR, WP>
impl<WR: WordWrite, WP: WriteParams> DeltaWrite<LittleEndian> for BufBitWriter<LittleEndian, WR, WP>
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<E: Endianness, WW, WP: WriteParams> FlatType for BufBitWriter<E, WW, WP>
impl<E: Endianness, WW, WP: WriteParams> FlatType for BufBitWriter<E, WW, WP>
Source§impl<WR: WordWrite, WP: WriteParams> GammaWrite<BigEndian> for BufBitWriter<BigEndian, WR, WP>
impl<WR: WordWrite, WP: WriteParams> GammaWrite<BigEndian> for BufBitWriter<BigEndian, WR, WP>
Source§impl<WR: WordWrite, WP: WriteParams> GammaWrite<LittleEndian> for BufBitWriter<LittleEndian, WR, WP>
impl<WR: WordWrite, WP: WriteParams> GammaWrite<LittleEndian> for BufBitWriter<LittleEndian, WR, WP>
Source§impl<E: Endianness, WW, WP: WriteParams> MemDbgImpl for BufBitWriter<E, WW, WP>where
WW: MemDbgImpl + FlatType + WordWrite,
WW::Word: MemDbgImpl + FlatType,
usize: MemDbgImpl + FlatType,
PhantomData<(E, WP)>: MemDbgImpl + FlatType,
impl<E: Endianness, WW, WP: WriteParams> MemDbgImpl for BufBitWriter<E, WW, WP>where
WW: MemDbgImpl + FlatType + WordWrite,
WW::Word: MemDbgImpl + FlatType,
usize: MemDbgImpl + FlatType,
PhantomData<(E, WP)>: MemDbgImpl + FlatType,
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, _memdbg_refs: &mut HashSet<usize>, ) -> 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, dbg_refs: &mut HashSet<usize>, ) -> Result<(), Error>
Source§fn _mem_dbg_depth_on_impl(
&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,
dbg_refs: &mut HashSet<usize>,
ref_display: RefDisplay,
) -> Result<(), Error>
fn _mem_dbg_depth_on_impl( &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, dbg_refs: &mut HashSet<usize>, ref_display: RefDisplay, ) -> 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<WR: WordWrite, WP: WriteParams> OmegaWrite<BigEndian> for BufBitWriter<BigEndian, WR, WP>
impl<WR: WordWrite, WP: WriteParams> OmegaWrite<BigEndian> for BufBitWriter<BigEndian, WR, WP>
Source§impl<WR: WordWrite, WP: WriteParams> OmegaWrite<LittleEndian> for BufBitWriter<LittleEndian, WR, WP>
impl<WR: WordWrite, WP: WriteParams> OmegaWrite<LittleEndian> for BufBitWriter<LittleEndian, WR, WP>
Source§impl<WR: WordWrite, WP: WriteParams> PiWrite<BigEndian> for BufBitWriter<BigEndian, WR, WP>
impl<WR: WordWrite, WP: WriteParams> PiWrite<BigEndian> for BufBitWriter<BigEndian, WR, WP>
Source§impl<WR: WordWrite, WP: WriteParams> PiWrite<LittleEndian> for BufBitWriter<LittleEndian, WR, WP>
impl<WR: WordWrite, WP: WriteParams> PiWrite<LittleEndian> for BufBitWriter<LittleEndian, WR, WP>
Source§impl<WW: WordWrite, WP: WriteParams> Write for BufBitWriter<BE, WW, WP>
Available on crate feature std only.
impl<WW: WordWrite, WP: WriteParams> Write for BufBitWriter<BE, WW, WP>
std only.Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)Source§impl<WW: WordWrite, WP: WriteParams> Write for BufBitWriter<LE, WW, WP>
Available on crate feature std only.
impl<WW: WordWrite, WP: WriteParams> Write for BufBitWriter<LE, WW, WP>
std only.Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)Source§impl<WR: WordWrite, WP: WriteParams> ZetaWrite<BigEndian> for BufBitWriter<BigEndian, WR, WP>
impl<WR: WordWrite, WP: WriteParams> ZetaWrite<BigEndian> for BufBitWriter<BigEndian, WR, WP>
Source§impl<WR: WordWrite, WP: WriteParams> ZetaWrite<LittleEndian> for BufBitWriter<LittleEndian, WR, WP>
impl<WR: WordWrite, WP: WriteParams> ZetaWrite<LittleEndian> for BufBitWriter<LittleEndian, WR, WP>
Auto Trait Implementations§
impl<E, WW, WP> Freeze for BufBitWriter<E, WW, WP>
impl<E, WW, WP> RefUnwindSafe for BufBitWriter<E, WW, WP>
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> UnsafeUnpin 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
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<E, B> ExpGolombWrite<E> for Bwhere
E: Endianness,
B: GammaWrite<E>,
impl<E, B> ExpGolombWrite<E> for Bwhere
E: Endianness,
B: GammaWrite<E>,
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>
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>
core::fmt::Write debug info 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>
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>
core::fmt::Write debug info about the structure memory
usage as mem_dbg_on, but expanding only up to
max_depth levels of nested structures.