38 releases
Uses old Rust 2015
0.3.17 | Mar 20, 2023 |
---|---|
0.3.16 | Jan 7, 2020 |
0.3.14 | Sep 9, 2019 |
0.3.13 | Jan 11, 2019 |
0.0.1 | Nov 20, 2014 |
#8 in Web programming
8,698,577 downloads per month
Used in 20,405 crates
(1,529 directly)
43KB
1K
SLoC
mime
Support MIME (Media Types) as strong types in Rust.
Usage
extern crate mime;
// common types are constants
let text = mime::TEXT_PLAIN;
// deconstruct Mimes to match on them
match (text.type_(), text.subtype()) {
(mime::TEXT, mime::PLAIN) => {
// plain text!
},
(mime::TEXT, _) => {
// structured text!
},
_ => {
// not text!
}
}
lib.rs
:
Mime
Mime is now Media Type, technically, but Mime
is more immediately
understandable, so the main type here is Mime
.
What is Mime?
Example mime string: text/plain
let plain_text: mime::Mime = "text/plain".parse().unwrap();
assert_eq!(plain_text, mime::TEXT_PLAIN);
Inspecting Mimes
let mime = mime::TEXT_PLAIN;
match (mime.type_(), mime.subtype()) {
(mime::TEXT, mime::PLAIN) => println!("plain text!"),
(mime::TEXT, _) => println!("structured text"),
_ => println!("not text"),
}