pub struct MimeMapper { /* private fields */ }Expand description
MIME type mapper for converting file descriptions to MIME types
Provides case-insensitive matching of file type descriptions to their corresponding MIME types.
§Examples
use libmagic_rs::mime::MimeMapper;
let mapper = MimeMapper::new();
assert_eq!(mapper.get_mime_type("ELF 64-bit executable"), Some("application/x-executable".to_string()));
assert_eq!(mapper.get_mime_type("PNG image data"), Some("image/png".to_string()));
assert_eq!(mapper.get_mime_type("unknown format"), None);Implementations§
Source§impl MimeMapper
impl MimeMapper
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new MIME mapper with hardcoded mappings
Includes mappings for common file types:
- Executables (ELF, PE32, Mach-O)
- Archives (ZIP, GZIP, TAR, RAR, 7Z)
- Images (JPEG, PNG, GIF, BMP, WEBP, TIFF, ICO)
- Documents (PDF, PostScript)
- Audio/Video (MP3, MP4, AVI, WAV)
- Web (HTML, XML, JSON, JavaScript, CSS)
- Text formats
Sourcepub fn get_mime_type(&self, description: &str) -> Option<String>
pub fn get_mime_type(&self, description: &str) -> Option<String>
Get MIME type for a file description
Performs case-insensitive matching against known file type keywords. Returns the best matching MIME type found in the description, preferring longer (more specific) keyword matches.
§Arguments
description- The file type description to match
§Returns
Some(String) with the MIME type if a match is found, None otherwise.
§Examples
use libmagic_rs::mime::MimeMapper;
let mapper = MimeMapper::new();
// Case-insensitive matching
assert_eq!(mapper.get_mime_type("ELF executable"), Some("application/x-executable".to_string()));
assert_eq!(mapper.get_mime_type("elf executable"), Some("application/x-executable".to_string()));
// Matches within longer descriptions
assert_eq!(mapper.get_mime_type("PNG image data, 800x600"), Some("image/png".to_string()));Trait Implementations§
Source§impl Clone for MimeMapper
impl Clone for MimeMapper
Source§fn clone(&self) -> MimeMapper
fn clone(&self) -> MimeMapper
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MimeMapper
impl Debug for MimeMapper
Auto Trait Implementations§
impl Freeze for MimeMapper
impl RefUnwindSafe for MimeMapper
impl Send for MimeMapper
impl Sync for MimeMapper
impl Unpin for MimeMapper
impl UnsafeUnpin for MimeMapper
impl UnwindSafe for MimeMapper
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
Mutably borrows from an owned value. Read more