Mode

Trait Mode 

Source
pub trait Mode {
    // Required methods
    fn length(decompressed_size: usize) -> usize;
    fn read<R: Read + Seek>(reader: &mut R) -> RefPackResult<Header>;
    fn write<W: Write + Seek>(
        header: Header,
        writer: &mut W,
    ) -> RefPackResult<()>;
}
Expand description

Represents a read and write format for a Header

This trait is entirely statically resolved and should only ever be implemented on structs which cannot be constructed. It has only associated functions, no methods, and only ever is referenced via generic arguments.

To implement your own commands, implement Mode on to a unit struct or unconstructable struct with one private member and no new method. read and write should be symmetrical, and a value fed in to read and then back out of write should yield the same result.

Required Methods§

Source

fn length(decompressed_size: usize) -> usize

Length of the header, used by some parsing

Source

fn read<R: Read + Seek>(reader: &mut R) -> RefPackResult<Header>

Reads from a Read + Seek reader and attempts to parse a header at the current position.

§Errors
  • [RefPackError::BadMagic]: Magic number failed verification
  • [RefPackError::Io]: Generic IO Error occurred during read
Source

fn write<W: Write + Seek>(header: Header, writer: &mut W) -> RefPackResult<()>

Writes to a Write + Seek writer and attempts to encode a header at the current position.

§Errors
  • [RefPackError::Io]: Generic IO Error occurred during write

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§