Skip to main content

FormatReader

Trait FormatReader 

Source
pub trait FormatReader: Send + Sync {
    // Required methods
    fn descriptor(&self) -> FormatDescriptor;
    fn sniff(&self, head: &[u8], path: &Path) -> Option<Detection>;
    fn open(&self, path: &Path) -> Result<Box<dyn Dataset>>;

    // Provided methods
    fn sniff_input(&self, head: &[u8], input: &Input) -> Option<Detection> { ... }
    fn open_input(&self, input: &Input) -> Result<Box<dyn Dataset>> { ... }
    fn reads_any_source(&self) -> bool { ... }
    fn assurance(&self) -> Option<&'static AssuranceProfile> { ... }
}
Expand description

A format implementation.

Required Methods§

Source

fn descriptor(&self) -> FormatDescriptor

Static description of the format (id, name, extensions, known gaps).

Source

fn sniff(&self, head: &[u8], path: &Path) -> Option<Detection>

Inspect the first bytes (up to 64 KiB) and the path; return None if this is not ours.

Source

fn open(&self, path: &Path) -> Result<Box<dyn Dataset>>

Open for reading.

Provided Methods§

Source

fn sniff_input(&self, head: &[u8], input: &Input) -> Option<Detection>

Like sniff, for an Input that may not be on the local file system. Readers whose detection looks at other files (a directory’s contents, a sibling) override it to look through Input::fs; the default calls sniff with the input’s path.

Source

fn open_input(&self, input: &Input) -> Result<Box<dyn Dataset>>

Open an Input: a local path, a buffer in memory, or a source the host provides. Readers that read through Input::fs override it (and make open a thin wrapper); the default opens local inputs by path and reports every other source as unsupported (exit 6), so a reader that does not read through byte sources never touches the local disk for a buffer that merely has the same name.

Source

fn reads_any_source(&self) -> bool

True when open_input reads any Input (memory, host callbacks), not only local paths.

Source

fn assurance(&self) -> Option<&'static AssuranceProfile>

The reader’s assurance profile (its crate’s src/assurance.rs): how to fingerprint a file’s variant and which variants the development corpus validates. None (the default) makes every file of the format unvalidated.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§