Skip to main content

Codec

Trait Codec 

Source
pub trait Codec {
    // Required methods
    fn format(&self) -> Format;
    fn magic_len(&self) -> usize;
    fn probe(&self, prefix: &[u8]) -> bool;
}
Expand description

Format sniffing.

Detection is by magic bytes only — extensions and MIME types are ignored (SPEC §Formats), because they are attacker-controlled hints rather than facts about the bytes.

Required Methods§

Source

fn format(&self) -> Format

The format this codec handles.

Source

fn magic_len(&self) -> usize

The number of leading bytes Codec::probe needs to decide.

Source

fn probe(&self, prefix: &[u8]) -> bool

Whether prefix looks like this format.

prefix may be shorter than Codec::magic_len if the source ended early; an implementation must then return false, never index blindly.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§