Trait Padding

Source
pub trait Padding {
    // Required methods
    fn max_size(&self) -> usize;
    fn pad<W: Write>(
        &self,
        last_byte: u8,
        byte_fill: u8,
        writer: &mut W,
    ) -> IOResult<()>;
    fn bits_left(&self, last_bytes: &[u8]) -> IOResult<usize>;
}
Expand description

Padding specifies what sort of padding should be used by BitReader/BitWriter

This trait can be used to implement custom padding of bits to a whole byte.

Required Methods§

Source

fn max_size(&self) -> usize

Get the maximum size of the padding.

This is used to determine how many bytes should be passed to bits_left

Source

fn pad<W: Write>( &self, last_byte: u8, byte_fill: u8, writer: &mut W, ) -> IOResult<()>

Pad the last bits of the stream.

This is called by BitWriter on drop to make sure the last bits are written to the output, using the specified padding. The padding is responsible for writing the last byte, or else it may lead to unintended loss of data.

Source

fn bits_left(&self, last_bytes: &[u8]) -> IOResult<usize>

Determine how many bits are left to read.

This is called by BitReader when encountering the last byte in the input stream. This will be called with the last n bytes of the input stream, where n is max_size(), or fewer, if there are fewer bytes in the whole input stream.

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.

Implementors§