mrmime
A small MIME type registry for Rust that allows easy lookup by MIME type string or file extension.
Why? Most apps only handle a small number of MIME types. This crate lets you declare exactly what you support and treats everything else as invalid. This is important in web applications that receive input from untrusted sources.
TODO: Generate built-in list from IANA media types or mime-db
Installation
Add this to your Cargo.toml:
[]
= "0.1"
We also support optional features for serde and diesel. A small curated set of common types ships by default via the builtin feature.
If you want to fully control which types are accepted, disable default features:
[]
= { = "0.1", = false } # no built-ins
[]
= "0.1"
= ["serde", "diesel"]
Usage
use ;
use FromStr;
// Built-ins are already present by default; you can add or replace by
// disabling default features (see above) and registering explicitly:
register_mime!
Built-in constants
When the builtin feature is enabled (default), you can refer to common types
via exported constants:
use ;
assert_eq!;
assert_eq!;
assert_eq!;
Tests
cargo test --all-features