pub struct RepositoryMimeDetector<'a> { /* private fields */ }Expand description
MIME detector backed by a MimeRepository.
Implementations§
Source§impl RepositoryMimeDetector<'static>
impl RepositoryMimeDetector<'static>
Sourcepub fn new() -> MimeResult<Self>
pub fn new() -> MimeResult<Self>
Sourcepub fn from_mime_config(config: MimeConfig) -> Self
pub fn from_mime_config(config: MimeConfig) -> Self
Source§impl<'a> RepositoryMimeDetector<'a>
impl<'a> RepositoryMimeDetector<'a>
Sourcepub fn with_repository(repository: &'a MimeRepository) -> Self
pub fn with_repository(repository: &'a MimeRepository) -> Self
Sourcepub fn with_repository_and_config(
repository: &'a MimeRepository,
config: MimeConfig,
) -> Self
pub fn with_repository_and_config( repository: &'a MimeRepository, config: MimeConfig, ) -> Self
Sourcepub fn core(&self) -> &MimeDetectorCore
pub fn core(&self) -> &MimeDetectorCore
Sourcepub fn core_mut(&mut self) -> &mut MimeDetectorCore
pub fn core_mut(&mut self) -> &mut MimeDetectorCore
Sourcepub fn repository(&self) -> &'a MimeRepository
pub fn repository(&self) -> &'a MimeRepository
Sourcepub fn detect_by_filename(&self, filename: &str) -> Option<String>
pub fn detect_by_filename(&self, filename: &str) -> Option<String>
Sourcepub fn detect_by_content(&self, bytes: &[u8]) -> Option<String>
pub fn detect_by_content(&self, bytes: &[u8]) -> Option<String>
Sourcepub fn detect_bytes(
&self,
bytes: &[u8],
filename: Option<&str>,
policy: MimeDetectionPolicy,
) -> Option<String>
pub fn detect_bytes( &self, bytes: &[u8], filename: Option<&str>, policy: MimeDetectionPolicy, ) -> Option<String>
Sourcepub fn detect_reader(
&self,
reader: &mut dyn ReadSeek,
filename: Option<&str>,
policy: MimeDetectionPolicy,
) -> MimeResult<Option<String>>
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.
Sourcepub fn detect_file(
&self,
file: &Path,
policy: MimeDetectionPolicy,
) -> MimeResult<Option<String>>
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.
Sourcepub fn guess_from_filename(&self, filename: &str) -> Vec<String>
pub fn guess_from_filename(&self, filename: &str) -> Vec<String>
Trait Implementations§
Source§impl<'a> Clone for RepositoryMimeDetector<'a>
impl<'a> Clone for RepositoryMimeDetector<'a>
Source§fn clone(&self) -> RepositoryMimeDetector<'a>
fn clone(&self) -> RepositoryMimeDetector<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Debug for RepositoryMimeDetector<'a>
impl<'a> Debug for RepositoryMimeDetector<'a>
Source§impl Default for RepositoryMimeDetector<'static>
impl Default for RepositoryMimeDetector<'static>
Source§impl<'a> StreamBasedMimeDetector for RepositoryMimeDetector<'a>
impl<'a> StreamBasedMimeDetector for RepositoryMimeDetector<'a>
Source§fn core(&self) -> &MimeDetectorCore
fn core(&self) -> &MimeDetectorCore
Gets the shared detector core.
Source§fn max_test_bytes(&self) -> usize
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>
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>>
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>)>
fn guess_from_reader_stream( &self, reader: &mut dyn ReadSeek, ) -> MimeResult<(Vec<String>, Vec<u8>)>
Source§fn guess_from_file_stream(
&self,
file: &Path,
) -> MimeResult<(Vec<String>, Vec<u8>)>
fn guess_from_file_stream( &self, file: &Path, ) -> MimeResult<(Vec<String>, Vec<u8>)>
Auto Trait Implementations§
impl<'a> Freeze for RepositoryMimeDetector<'a>
impl<'a> !RefUnwindSafe for RepositoryMimeDetector<'a>
impl<'a> Send for RepositoryMimeDetector<'a>
impl<'a> Sync for RepositoryMimeDetector<'a>
impl<'a> Unpin for RepositoryMimeDetector<'a>
impl<'a> UnsafeUnpin for RepositoryMimeDetector<'a>
impl<'a> !UnwindSafe for RepositoryMimeDetector<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, D> IntoConfigDefault<T> for Dwhere
D: IntoValueDefault<T>,
impl<T, D> IntoConfigDefault<T> for Dwhere
D: IntoValueDefault<T>,
Source§fn into_config_default(self) -> T
fn into_config_default(self) -> T
T.Source§impl<T> IntoValueDefault<T> for T
impl<T> IntoValueDefault<T> for T
Source§fn into_value_default(self) -> T
fn into_value_default(self) -> T
Source§impl<T> MimeDetector for Twhere
T: MimeDetectorBackend,
impl<T> MimeDetector for Twhere
T: MimeDetectorBackend,
Source§fn detect_by_filename(&self, filename: &str) -> Option<String>
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>
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>
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>
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>
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 Twhere
T: StreamBasedMimeDetector,
impl<T> MimeDetectorBackend for Twhere
T: StreamBasedMimeDetector,
Source§fn core(&self) -> &MimeDetectorCore
fn core(&self) -> &MimeDetectorCore
Gets the shared detector core.
Source§fn max_test_bytes(&self) -> usize
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>
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>
fn guess_from_content(&self, content: &[u8]) -> Result<Vec<String>, MimeError>
Guesses MIME type names from content bytes.