pub struct FormatMeta {
pub id: FormatId,
pub kind: FormatKind,
pub extensions: &'static [&'static str],
pub magics: &'static [MagicRule],
pub priority: i16,
pub confirm: Option<ConfirmFn>,
pub magic_optional: bool,
}Expand description
Registration metadata for one format.
Fields§
§id: FormatId§kind: FormatKind§extensions: &'static [&'static str]Extensions without the leading dot, lowercase. e.g. ["gz", "tgz"].
magics: &'static [MagicRule]§priority: i16Breaks ties when several formats share a magic. Higher wins.
The ZIP family is why this exists: jar, apk, docx, epub, odt and zip all
begin PK\x03\x04, so longest-magic-wins cannot separate them. Rank the
base format above its derivatives, and a bare stream resolves to the
base while a derivative is reached by extension.
confirm: Option<ConfirmFn>The format’s confirmation of its own magic hits — see ConfirmFn.
None from Self::codec and Self::container: a format that
registers no function is treated as confirming every hit, so adding
the hook changes nothing for a format until it opts in with
Self::with_confirm.
magic_optional: boolThe format’s writers can emit a stream its magic does not match, so
a missing magic is not by itself a refusal: a v7 tar has no ustar
at 257, and an empty tar is zero blocks. Set by
Self::with_magic_optional; tar is the one format that needs it.
Without it, crate::registry::Registry::confirm refuses any prefix
the format’s own magic does not match before its ConfirmFn runs,
because that function judges only “a prefix its magic already
matched” — a .pak file named for arc but beginning 05 00 read as
arc’s method 0, an empty archive, and passed.
Implementations§
Source§impl FormatMeta
impl FormatMeta
pub const fn codec( id: FormatId, extensions: &'static [&'static str], magics: &'static [MagicRule], ) -> Self
pub const fn container( id: FormatId, extensions: &'static [&'static str], magics: &'static [MagicRule], ) -> Self
pub const fn with_priority(self, priority: i16) -> Self
Sourcepub const fn with_confirm(self, f: ConfirmFn) -> Self
pub const fn with_confirm(self, f: ConfirmFn) -> Self
Registers f as this format’s confirmation — see ConfirmFn.
Sourcepub const fn with_magic_optional(self) -> Self
pub const fn with_magic_optional(self) -> Self
Marks the format as one whose writers may omit its magic — see
Self::magic_optional.