pub trait BitWrite<E: Endianness> {
    type Error: Error;

    // Required methods
    fn write_bits(&mut self, value: u64, n: usize) -> Result<usize, Self::Error>;
    fn write_unary_param<const USE_TABLE: bool>(
        &mut self,
        value: u64
    ) -> Result<usize, Self::Error>;
    fn flush(self) -> Result<(), Self::Error>;

    // Provided method
    fn write_unary(&mut self, value: u64) -> Result<usize, Self::Error> { ... }
}
Expand description

Sequential, streaming bit-by-bit writes.

This trait specify basic operation over which codes can be implemented by traits such as crate::codes::GammaWriteParam.

Required Associated Types§

Required Methods§

source

fn write_bits(&mut self, value: u64, n: 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.

Implementors should check the value of n when the checks feature is enabled and panic if it is greater than 64. Moreover, under the same conditions they should check that the remaining bits of value are zero.

source

fn write_unary_param<const USE_TABLE: bool>( &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.

This version of the method has a constant parameter deciding whether to use an encoding table. You should rather use BitWrite::write_unary, which uses the default choice of the implementing type.

source

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

Flush the buffer, consuming the bit stream.

Provided Methods§

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.

This version of the method uses the version of of BitWrite::write_unary_param selected as default by the implementing type. The default implementation uses a table.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<E: Endianness, BW: BitWrite<E>, const PRINT: bool> BitWrite<E> for CountBitWriter<E, BW, PRINT>

§

type Error = <BW as BitWrite<E>>::Error

source§

impl<E: Endianness, W: BitWrite<E>> BitWrite<E> for DbgBitWriter<E, W>

§

type Error = <W as BitWrite<E>>::Error

source§

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

§

type Error = <WW as WordWrite>::Error

source§

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

§

type Error = <WW as WordWrite>::Error