Skip to main content

Codec

Trait Codec 

Source
pub trait Codec: Send + Sync {
    // Required methods
    fn id(&self) -> FormatId;
    fn caps(&self) -> CodecCaps;
    fn decoder(
        &self,
        src: Box<dyn Source>,
        o: &DecodeOpts,
    ) -> Result<Box<dyn Source>>;
    fn encoder(
        &self,
        dst: Box<dyn Write + Send>,
        o: &EncodeOpts,
    ) -> Result<Box<dyn Sink>>;

    // Provided method
    fn check_encode_opts(&self, _o: &EncodeOpts) -> Result<()> { ... }
}
Expand description

A byte-stream transform. Knows nothing about files, names, or entries.

Required Methods§

Source

fn id(&self) -> FormatId

Source

fn caps(&self) -> CodecCaps

Source

fn decoder( &self, src: Box<dyn Source>, o: &DecodeOpts, ) -> Result<Box<dyn Source>>

Decodes src. Returns a Source rather than a bare reader so a codec carrying a frame index can advertise seekability to the layer above; forward-only codecs wrap their reader in crate::StreamOnly.

Source

fn encoder( &self, dst: Box<dyn Write + Send>, o: &EncodeOpts, ) -> Result<Box<dyn Sink>>

Provided Methods§

Source

fn check_encode_opts(&self, _o: &EncodeOpts) -> Result<()>

Validates encode options without touching the filesystem.

ops calls this before opening any destination, so a rejected option costs nothing — no temp file created, no existing file disturbed. The default accepts everything, for codecs with no options to reject.

With one codec this looks like ceremony. With nine, each carrying its own level range, “validate before touching the filesystem” has to be a contract rather than a habit: in Phase 1b an invalid level created and then deleted a file for nothing.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§