Skip to main content

IdentifyMethod

Enum IdentifyMethod 

Source
pub enum IdentifyMethod {
    Magic(&'static [u8]),
    MultipleMagic(&'static [&'static [u8]]),
    Extension(&'static str),
    Extensions(&'static [&'static str]),
    Name(&'static str),
    Names(&'static [&'static str]),
}
Expand description

Fast, declarative way to identify a content type without running custom code.

A ContentIdentifier can return one of these variants from identify_method so the scanner can build efficient matchers (tries, magic tables, etc.) once and reuse them for every scanned object.

If none of the variants fit your identifier, return None from identify_method and perform your own check inside validate.

Magic patterns (Magic, MultipleMagic) must be at most 16 bytes. The scanner only feeds the matcher the first 16 bytes of content, and only when at least one identifier registered such a pattern; ScannerBuilder::build panics if a registered magic is longer. To match bytes past that window, return None from identify_method and call Content::read in validate.

Variants§

§

Magic(&'static [u8])

Content whose first bytes exactly match this magic sequence.

The sequence must be at most 16 bytes. Longer patterns can never match (the scanner reads only content.read(0, 16)) and cause ScannerBuilder::build to panic. That 16-byte read is performed only when at least one identifier registered a Magic or MultipleMagic pattern.

§

MultipleMagic(&'static [&'static [u8]])

Content whose first bytes match any of these magic sequences.

Each sequence must be at most 16 bytes; see Magic.

§

Extension(&'static str)

Content whose file extension matches this string (ASCII case-insensitive, without the leading dot).

Notes.TXT matches Extension("txt"); a registered pattern "JPG" matches photo.jpg.

§

Extensions(&'static [&'static str])

Content whose file extension matches any of these strings (ASCII case-insensitive, without the leading dot).

§

Name(&'static str)

Content whose file name (basename) matches this string (ASCII case-insensitive).

makefile and MAKEFILE both match Name("Makefile").

§

Names(&'static [&'static str])

Content whose file name (basename) matches any of these strings (ASCII case-insensitive).

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.