⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

MimeDatabase

Struct MimeDatabase 

Source
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

Source

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)
Source

pub fn detect_mime(filename: &str, header_bytes: Option<&[u8]>) -> MimeType

Detect the MIME type of a file.

Detection order:

  1. Magic byte signatures (if header_bytes is Some)
  2. File extension
  3. MimeType::Unknown fallback
Source

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).

Source

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.

Source

pub fn category(mime: &MimeType) -> MimeCategory

Return the broad category for a MIME type.

Source

pub fn mime_to_str(mime: &MimeType) -> &'static str

Return the standard MIME type string (e.g. "text/plain").

Source

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.

Trait Implementations§

Source§

impl Default for MimeDatabase

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for MimeDatabase

§

impl RefUnwindSafe for MimeDatabase

§

impl Send for MimeDatabase

§

impl Sync for MimeDatabase

§

impl Unpin for MimeDatabase

§

impl UnwindSafe for MimeDatabase

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

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

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.