pub trait FileCategorizer: Sync + Send {
// Required methods
fn name(&self) -> &'static str;
fn categories(&self) -> &'static [&'static str];
fn categorize(&self, path: &Path, data: &[u8]) -> Option<Categorization>;
// Provided method
fn first_byte_hint(&self) -> Option<&'static [u8]> { ... }
}Expand description
One file-level categorizer.
Implementations should be:
- Pure-functional: same input → same output, no I/O.
- Deterministic: no clocks, no RNG, no system state.
- Cheap to refuse: header parsing should bail on the first mismatched magic byte, not scan the whole file.
Categorizers are tried in registration order. The first one to
return Some(Categorization) wins; later categorizers are not
consulted. Order matters: register specific categorizers before
generic ones.
Required Methods§
Sourcefn categories(&self) -> &'static [&'static str]
fn categories(&self) -> &'static [&'static str]
Categories this categorizer can emit. Used for diagnostic dumps; does not affect dispatch.
Sourcefn categorize(&self, path: &Path, data: &[u8]) -> Option<Categorization>
fn categorize(&self, path: &Path, data: &[u8]) -> Option<Categorization>
Categorize a file by its path and full contents.
Returns Some(Categorization) if this categorizer claims the
file, None to defer to the next categorizer in the registry
(or to the FastCDC fallback path).
Implementations should not read the file from disk — data
is already in hand. Path is provided for extension-based
hints when magic-byte detection is ambiguous.
Provided Methods§
Sourcefn first_byte_hint(&self) -> Option<&'static [u8]>
fn first_byte_hint(&self) -> Option<&'static [u8]>
The set of first bytes that this categorizer can possibly
match. The registry uses this to skip categorizers without
a function call when data[0] isn’t in the set.
Return None (default) to opt out of the early-exit
optimisation — the categorizer is always tried. Return
Some(&[bytes]) to enable early-exit: the registry checks
data[0] and skips this categorizer if it’s not in the set.
Example: ELF categorizer returns Some(&[0x7F]) — it can
only match files whose first byte is 0x7F.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".