Skip to main content

FormatMeta

Struct FormatMeta 

Source
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: i16

Breaks 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: bool

The 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

Source

pub const fn codec( id: FormatId, extensions: &'static [&'static str], magics: &'static [MagicRule], ) -> Self

Source

pub const fn container( id: FormatId, extensions: &'static [&'static str], magics: &'static [MagicRule], ) -> Self

Source

pub const fn with_priority(self, priority: i16) -> Self

Source

pub const fn with_confirm(self, f: ConfirmFn) -> Self

Registers f as this format’s confirmation — see ConfirmFn.

Source

pub const fn with_magic_optional(self) -> Self

Marks the format as one whose writers may omit its magic — see Self::magic_optional.

Trait Implementations§

Source§

impl Clone for FormatMeta

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for FormatMeta

Source§

impl Debug for FormatMeta

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.