Skip to main content

RepositoryMimeDetector

Struct RepositoryMimeDetector 

Source
pub struct RepositoryMimeDetector<'a> { /* private fields */ }
Expand description

MIME detector backed by a MimeRepository.

Implementations§

Source§

impl RepositoryMimeDetector<'static>

Source

pub fn new() -> MimeResult<Self>

Creates a detector using the embedded freedesktop MIME repository.

§Returns

A repository-backed detector.

§Errors

The embedded database is parsed from crate resources and is expected to be valid; this method keeps a Result return type for API consistency.

Source

pub fn from_mime_config(config: MimeConfig) -> Self

Creates a detector using the embedded repository and explicit config.

§Parameters
  • config: MIME detector configuration.
§Returns

A repository-backed detector.

Source§

impl<'a> RepositoryMimeDetector<'a>

Source

pub fn with_repository(repository: &'a MimeRepository) -> Self

Creates a detector using an explicit repository.

§Parameters
  • repository: Repository used for all detections.
§Returns

A detector borrowing repository.

Source

pub fn with_repository_and_config( repository: &'a MimeRepository, config: MimeConfig, ) -> Self

Creates a detector using an explicit repository and config.

§Parameters
  • repository: Repository used for all detections.
  • config: MIME detector configuration.
§Returns

A detector borrowing repository.

Source

pub fn core(&self) -> &MimeDetectorCore

Gets the shared detector core.

§Returns

Shared detector core.

Source

pub fn core_mut(&mut self) -> &mut MimeDetectorCore

Gets mutable shared detector core.

§Returns

Mutable shared detector core.

Source

pub fn repository(&self) -> &'a MimeRepository

Gets the underlying repository.

§Returns

Repository used by this detector.

Source

pub fn detect_by_filename(&self, filename: &str) -> Option<String>

Detects a MIME type from a filename.

§Parameters
  • filename: Path or basename to inspect.
§Returns

First MIME type matched by filename, or None.

Source

pub fn detect_by_content(&self, bytes: &[u8]) -> Option<String>

Detects a MIME type from content bytes.

§Parameters
  • bytes: Content prefix to inspect.
§Returns

First MIME type matched by magic, or None.

Source

pub fn detect_bytes( &self, bytes: &[u8], filename: Option<&str>, policy: MimeDetectionPolicy, ) -> Option<String>

Detects a MIME type from content bytes and an optional filename.

§Parameters
  • bytes: Content prefix to inspect.
  • filename: Optional path or basename used for glob detection.
  • policy: Strategy for resolving filename and content results.
§Returns

Selected MIME type name, or None.

Source

pub fn detect_reader( &self, reader: &mut dyn ReadSeek, filename: Option<&str>, policy: MimeDetectionPolicy, ) -> MimeResult<Option<String>>

Detects a MIME type from a seekable reader without consuming its position.

§Parameters
  • reader: Reader to inspect. The original stream position is restored.
  • filename: Optional path or basename used for glob detection.
  • policy: Strategy for resolving filename and content results.
§Returns

Selected MIME type name, or None.

§Errors

Returns MimeError::Io when reading or seeking fails.

Source

pub fn detect_file( &self, file: &Path, policy: MimeDetectionPolicy, ) -> MimeResult<Option<String>>

Detects a MIME type from a local file.

§Parameters
  • file: Local file path to open.
  • policy: Strategy for resolving filename and content results.
§Returns

Selected MIME type name, or None.

§Errors

Returns MimeError::Io when the file cannot be opened or read.

Source

pub fn guess_from_filename(&self, filename: &str) -> Vec<String>

Guesses MIME type names from filename rules.

§Parameters
  • filename: Filename or path.
§Returns

Candidate MIME type names.

Source

pub fn guess_from_content(&self, bytes: &[u8]) -> Vec<String>

Guesses MIME type names from content magic rules.

§Parameters
  • bytes: Content bytes to inspect.
§Returns

Candidate MIME type names.

Trait Implementations§

Source§

impl<'a> Clone for RepositoryMimeDetector<'a>

Source§

fn clone(&self) -> RepositoryMimeDetector<'a>

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<'a> Debug for RepositoryMimeDetector<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for RepositoryMimeDetector<'static>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a> StreamBasedMimeDetector for RepositoryMimeDetector<'a>

Source§

fn core(&self) -> &MimeDetectorCore

Gets the shared detector core.

Source§

fn max_test_bytes(&self) -> usize

Gets the maximum content prefix length from the repository.

Source§

fn guess_from_filename(&self, filename: &str) -> Vec<String>

Guesses MIME type names from filename rules.

Source§

fn guess_from_content_bytes(&self, content: &[u8]) -> MimeResult<Vec<String>>

Guesses MIME type names from content magic rules.

Source§

fn guess_from_reader_stream( &self, reader: &mut dyn ReadSeek, ) -> MimeResult<(Vec<String>, Vec<u8>)>

Guesses MIME type names from a seekable reader. Read more
Source§

fn guess_from_file_stream( &self, file: &Path, ) -> MimeResult<(Vec<String>, Vec<u8>)>

Guesses MIME type names from a local file. 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, D> IntoConfigDefault<T> for D
where D: IntoValueDefault<T>,

Source§

fn into_config_default(self) -> T

Converts this fallback value into T.
Source§

impl<T> IntoValueDefault<T> for T

Source§

fn into_value_default(self) -> T

Converts this argument into the default value.
Source§

impl<T> MimeDetector for T

Source§

fn detect_by_filename(&self, filename: &str) -> Option<String>

Detects a MIME type from filename candidates.

Source§

fn detect_by_content(&self, content: &[u8]) -> Option<String>

Detects a MIME type from content candidates.

Source§

fn detect( &self, content: &[u8], filename: Option<&str>, policy: MimeDetectionPolicy, ) -> Option<String>

Detects a MIME type from content bytes and an optional filename.

Source§

fn detect_reader( &self, reader: &mut dyn ReadSeek, filename: Option<&str>, policy: MimeDetectionPolicy, ) -> Result<Option<String>, MimeError>

Detects a MIME type from a seekable reader.

Source§

fn detect_file( &self, file: &Path, policy: MimeDetectionPolicy, ) -> Result<Option<String>, MimeError>

Detects a MIME type from a local file.

Source§

impl<T> MimeDetectorBackend for T

Source§

fn core(&self) -> &MimeDetectorCore

Gets the shared detector core.

Source§

fn max_test_bytes(&self) -> usize

Gets the maximum content prefix length needed by this detector.

Source§

fn guess_from_filename(&self, filename: &str) -> Vec<String>

Guesses MIME type names from filename rules.

Source§

fn guess_from_content(&self, content: &[u8]) -> Result<Vec<String>, MimeError>

Guesses MIME type names from content bytes.

Source§

fn guess_from_reader( &self, reader: &mut dyn ReadSeek, ) -> Result<(Vec<String>, Vec<u8>), MimeError>

Delegates reader inspection to the stream-based hook.

Source§

fn guess_from_file( &self, file: &Path, ) -> Result<(Vec<String>, Vec<u8>), MimeError>

Delegates local-file inspection to the stream-based hook.

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.