pub struct MimeDatabase { /* private fields */ }Expand description
Central database for MIME type detection and application dispatch.
Contains a set of built-in default associations (populated in new()) plus
user-registered custom associations that take priority.
Implementations§
Source§impl MimeDatabase
impl MimeDatabase
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new MIME database populated with default associations.
Default dispatch table:
- Text types -> Text Editor (
/bin/text-editor) - Image types -> Image Viewer (
/bin/image-viewer) - ELF binaries -> Terminal (
/bin/terminal) - Directories -> File Manager (
/bin/file-manager) - Everything else -> Text Editor (fallback)
Sourcepub fn detect_mime(filename: &str, header_bytes: Option<&[u8]>) -> MimeType
pub fn detect_mime(filename: &str, header_bytes: Option<&[u8]>) -> MimeType
Detect the MIME type of a file.
Detection order:
- Magic byte signatures (if
header_bytesisSome) - File extension
MimeType::Unknownfallback
Sourcepub fn open_with(&self, mime: &MimeType) -> Option<&MimeAssociation>
pub fn open_with(&self, mime: &MimeType) -> Option<&MimeAssociation>
Get the default application for a MIME type.
Checks custom associations first, then falls back to the built-in
default table. Returns None only if both tables are empty (should
not happen with default construction).
Sourcepub fn register_association(
&mut self,
mime_type: MimeType,
app_name: String,
app_exec: String,
)
pub fn register_association( &mut self, mime_type: MimeType, app_name: String, app_exec: String, )
Register a custom MIME association.
Custom associations take priority over built-in defaults. If an association for the same MIME type already exists in the custom list, it is replaced.
Sourcepub fn category(mime: &MimeType) -> MimeCategory
pub fn category(mime: &MimeType) -> MimeCategory
Return the broad category for a MIME type.
Sourcepub fn mime_to_str(mime: &MimeType) -> &'static str
pub fn mime_to_str(mime: &MimeType) -> &'static str
Return the standard MIME type string (e.g. "text/plain").
Sourcepub fn icon_color(mime: &MimeType) -> u32
pub fn icon_color(mime: &MimeType) -> u32
Return a BGRA color for the file type icon in the file manager.
Colors are chosen for quick visual identification:
- Text/code files: muted shades
- Images: bright green
- Audio: orange
- Video: magenta
- Archives: yellow
- Executables: red
- Directories: blue (matches file_manager.rs existing
0x55AAFF)
The returned value is packed BGRA (B in bits 0-7, G in 8-15, R in 16-23, A in 24-31) matching the framebuffer byte order.