#media-type #mime #no-std

no-std mime2ext

Given a mimetype, suggest a file extension

11 releases

Uses old Rust 2015

0.1.54 Mar 18, 2025
0.1.53 Aug 16, 2024
0.1.52 Feb 21, 2022
0.1.51 Nov 9, 2021
0.1.2 Mar 3, 2021

#110 in Filesystem

Download history 5341/week @ 2026-01-19 5540/week @ 2026-01-26 6664/week @ 2026-02-02 6669/week @ 2026-02-09 14792/week @ 2026-02-16 10835/week @ 2026-02-23 13331/week @ 2026-03-02 17306/week @ 2026-03-09 15756/week @ 2026-03-16 18628/week @ 2026-03-23 16297/week @ 2026-03-30 16525/week @ 2026-04-06 17516/week @ 2026-04-13 17489/week @ 2026-04-20 18772/week @ 2026-04-27 16340/week @ 2026-05-04

71,929 downloads per month
Used in 51 crates (9 directly)

MIT license

29KB
191 lines

mime2ext

Crates.io API reference MSRV CI

A simple compact crate to look up a file extension for a mime type.

It embeds part of the mime-db database, packed efficiently into around 20 KiB. There are no dependencies, and it's no_std-compatible.

Example

use mime2ext::mime2ext;

assert_eq!(mime2ext("image/png"), Some("png"));
assert_eq!(mime2ext("application/octet-stream"), Some("bin"));
assert_eq!(mime2ext("text/html; charset=UTF-8"), Some("html"));
assert_eq!(mime2ext("nonexistent/mimetype"), None);
assert_eq!(mime2ext("invalid-mimetype"), None);

Interoperability with mime

mime's Mime type is supported through its implementation of AsRef<str>, without any dependency on the crate:

use mime::{Mime, TEXT_PLAIN};
use mime2ext::mime2ext;

assert_eq!(mime2ext(TEXT_PLAIN), Some("txt"));
let mime: Mime = "text/xml; charset=latin1".parse()?;
assert_eq!(mime2ext(&mime), Some("xml"));

Versioning

mime2ext includes a static version of mime-db. A new version of mime2ext has to be released for each new version of mime-db.

mime2ext's version number tracks that of mime-db. mime2ext version 0.1.49 corresponds to mime-db version 1.49.0.

See CHANGELOG.md for differences between versions, including relevant changes to mime-db.

License

Both mime2ext and mime-db are licensed under the MIT license. See LICENSE and mime-db/LICENSE.

See also

  • mime_guess, which mainly converts in the opposite direction. It can also convert mime types to extensions but often suggests rarely-used extensions, like jpe for image/jpeg.

No runtime deps