3 releases (stable)

1.1.20260327 Apr 10, 2026
1.0.20260327 Apr 6, 2026
1.0.20260327-1 Apr 7, 2026
0.1.0 Apr 6, 2026
0.0.1 Apr 6, 2026

#162 in Audio

MIT license

720KB
16K SLoC

libmime

Auto-generated IANA media type constants for Rust.

This crate provides every media type registered in the IANA Media Types Registry as compile-time constants. It is updated automatically on a weekly schedule via CI, with no human intervention required.

Usage

Add the dependency:

cargo add libmime

Use a constant directly:

use libmime::{APPLICATION_JSON, TEXT_HTML};

let content_type = APPLICATION_JSON;
println!("{}", content_type); // application/json

Look up a type from a string:

use libmime::lookup;

if let Some(mime) = lookup("image/png") {
    println!("{}", mime.subtype()); // png
}

Lookup is case-insensitive. It returns None for types not present in the IANA registry.

Features

Feature Default Description
std Yes Enables phf-backed O(1) lookup.

Without std, lookup falls back to a binary search over a sorted static table. The core Mime type is always available in no_std environments with no allocator requirement.

[dependencies]
libmime = { version = "1", default-features = false }

The Mime Type

Mime is Copy, Clone, Eq, Hash, and consists entirely of &'static str references and a fieldless enum. There are no heap allocations.

pub struct Mime {
    pub top: TopLevel,
    pub sub: &'static str,
    pub suffix: Option<&'static str>,
}

TopLevel covers the ten IANA top-level types:

  • Application
  • Audio
  • Font
  • Haptics
  • Image
  • Message
  • Model
  • Multipart
  • Text
  • Video

Versioning

This crate uses the major.minor.IANA_UPDATED pattern, where patch is optional, and IANA_UPDATED is the date provided in the page Media Types.xhtml under the Last Updated section, minus the dashes.

The date is formatted as YYYYMMDD

Minimum Supported Rust Version

Due to our dependency on the phf crate for std features, our MSRV remains in line with theirs. Currently that is an MSRV of 1.66, if phf changes theirs, we will follow.

License

MIT

Dependencies