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§
Sourcefn magic_len(&self) -> usize
fn magic_len(&self) -> usize
The number of leading bytes Codec::probe needs to decide.
Sourcefn probe(&self, prefix: &[u8]) -> bool
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".