#mime #extension #media-types #filesystem #no-std

no-std mime2ext

Given a mimetype, suggest a file extension

8 releases

Uses old Rust 2015

0.1.51 Nov 9, 2021
0.1.50 Sep 16, 2021
0.1.49 Aug 1, 2021
0.1.4 May 31, 2021
0.1.1 Feb 15, 2021

#52 in Filesystem

Download history 528/week @ 2021-09-27 464/week @ 2021-10-04 668/week @ 2021-10-11 601/week @ 2021-10-18 803/week @ 2021-10-25 924/week @ 2021-11-01 1057/week @ 2021-11-08 1393/week @ 2021-11-15 994/week @ 2021-11-22 970/week @ 2021-11-29 576/week @ 2021-12-06 1020/week @ 2021-12-13 751/week @ 2021-12-20 614/week @ 2021-12-27 733/week @ 2022-01-03 952/week @ 2022-01-10

3,349 downloads per month
Used in 2 crates

MIT license

181 lines


Crates.io API reference MSRV CI

A simple 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.

It was created for xh, which does at most one lookup per run. It prioritizes a small size over a high speed, but it should nevertheless be fast enough for most purposes.


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"));


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.


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.

No runtime deps