pub trait BitRead<E: Endianness> {
type Error: Error + Send + Sync + 'static;
type PeekWord: AsPrimitive<u64>;
const PEEK_BITS: usize;
// Required methods
fn read_bits(&mut self, num_bits: usize) -> Result<u64, Self::Error>;
fn peek_bits(&mut self, n: usize) -> Result<Self::PeekWord, Self::Error>;
fn skip_bits(&mut self, n: usize) -> Result<(), Self::Error>;
fn read_unary(&mut self) -> Result<u64, Self::Error>;
// Provided method
fn copy_to<F: Endianness, W: BitWrite<F>>(
&mut self,
bit_write: &mut W,
n: u64,
) -> Result<(), CopyError<Self::Error, W::Error>> { ... }
}Expand description
Sequential, streaming bit-by-bit reads.
This trait specifies basic operations over which codes can be implemented by
traits such as GammaReadParam.
To quickly read complex codes, such traits may use the
peek_bits method to read a few bits in advance and
then use a table to decode them. For this to happen correctly,
peek_bits must return a sufficient number of bits.
Each table module provides a check_read_table const fn that can be used
in a const { } block to verify at compile time that the peek word is
large enough.
Please see the documentation of the impls module for more
details.
Required Associated Constants§
Required Associated Types§
type Error: Error + Send + Sync + 'static
Sourcetype PeekWord: AsPrimitive<u64>
type PeekWord: AsPrimitive<u64>
The type we can read from the stream without advancing.
Required Methods§
Sourcefn read_bits(&mut self, num_bits: usize) -> Result<u64, Self::Error>
fn read_bits(&mut self, num_bits: usize) -> Result<u64, Self::Error>
Reads num_bits bits and returns them in the lowest bits.
Implementors should check the value of num_bits when in test mode
and panic if it is greater than 64.
Sourcefn peek_bits(&mut self, n: usize) -> Result<Self::PeekWord, Self::Error>
fn peek_bits(&mut self, n: usize) -> Result<Self::PeekWord, Self::Error>
Peeks at n bits without advancing the stream position.
n must be nonzero, and at most Self::PeekWord::BITS.
Sourcefn skip_bits(&mut self, n: usize) -> Result<(), Self::Error>
fn skip_bits(&mut self, n: usize) -> Result<(), Self::Error>
Skip n bits from the stream.
When moving forward by a small amount of bits, this method might be
more efficient than BitSeek::set_bit_pos.
Sourcefn read_unary(&mut self) -> Result<u64, Self::Error>
fn read_unary(&mut self) -> Result<u64, Self::Error>
Reads a unary code.
Implementations are required to support the range [0 . . 2⁶⁴ – 1).
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.