mime_to_ext

Crates.iomime_to_ext
lib.rsmime_to_ext
version0.1.12
created_at2025-11-04 11:19:09.839381+00
updated_at2025-11-11 03:22:16.825406+00
descriptionno_std MIME ↔ extension lookup from embedded JSON, no OS files
homepagehttps://github.com/GaneshJadhavOnGitHub/mime_to_ext
repositoryhttps://github.com/GaneshJadhavOnGitHub/mime_to_ext
max_upload_size
id1916140
size132,348
GANESH KAMLAKAR JADHAV (GaneshJadhavOnGitHub)

documentation

https://docs.rs/mime_to_ext/latest/mime_to_ext/

README

mime_to_ext

Rust 1.85+ no_std Crates.io GitHub Docs.rs

no_std MIME ↔ extension lookup using lazily-loaded embedded JSON with no runtime dependency on OS mime files.

MSRV: 1.85 (2024 edition)

🏷️ Crate Overview

mime_to_ext is a no_std crate that ships an embedded, lazily-loaded JSON mapping of verified MIME-type ↔ extension pairs, giving you robust, cross-platform runtime lookup without touching OS mime files. Unlike other crates that rely on system files or partial datasets, mime_to_ext offers one of the most complete MIME–extension mappings available in Rust — covering more than 1,100 MIME entries from diverse, reputable sources.


Why mime_to_ext?

Most crates that handle MIME lookups rely on operating system's limited datasets which can lead to missing mappings.

mime_to_ext eliminates this by combining data from multiple independent and widely used MIME databases into a single unified dataset.

This approach ensures:

  • Cross-platform reliability - No dependency on operating systems's limited datasets
  • Broadest coverage - Over 1,100 verified MIME–extension pairs
  • Runtime lookups - Without I/O overhead as the dataset is already embedded

⚙️ How it works

The crate uses a precompiled JSON database that merges and normalizes data from several trusted MIME registries and open datasets. The merging process removes duplicates, resolves conflicts, and standardizes both MIME types and extensions to provide clean bidirectional lookup — all accessible at runtime.


Usage

Add this to your Cargo.toml:

[dependencies]
mime_to_ext = "0.1.12"

Example


use mime_to_ext::{mime_to_ext, ext_to_mime};

fn main() {
    // MIME → All extensions
    if let Some(exts) = mime_to_ext("audio/mpeg") {
        println!("Extensions for audio/mpeg: {}", exts.join(", "));
    } else {
        println!("No extensions found for audio/mpeg");
    }

    // Extension → Single canonical MIME type
    if let Some(mime) = ext_to_mime("png") {
        println!("The MIME type for .png is: {}", mime);
    } else {
        println!("No MIME type found for .png");
    }
}

Test

assert_eq!(mime_to_ext("audio/mpeg"), Some(&["mp3", "mp1", "mp2"][..]));
assert_eq!(mime_to_ext("image/png"), Some(&["png"][..]));
assert_eq!(ext_to_mime("png"), Some("image/png"));
assert_eq!(ext_to_mime("mp1"), Some("audio/mpeg"));

assert_eq!(mime_to_ext("foo/bar"), None);
assert_eq!(ext_to_mime("qqq"), None);

Quick Links

🔗 Source code: GitHub
📦 Rust crate: crates.io
📚 Documentation: Docs.rs

License

Licensed under either of Apache-2.0 or MIT.

Commit count: 0

cargo fmt