Expand description
About
This crate provides two MediaType structs: MediaType
and MediaTypeBuf
.
MediaType
does not copy data during parsing and just holds reference to the original string. It is also const-constructible.MediaTypeBuf
is an owned and immutable version ofMediaType
.
use mediatype::{names::*, MediaType, MediaTypeBuf};
const TEXT_PLAIN: MediaType = MediaType::new(TEXT, PLAIN);
let text_plain: MediaTypeBuf = "text/plain".parse().unwrap();
assert_eq!(text_plain, TEXT_PLAIN);
match (text_plain.ty(), text_plain.subty()) {
("text", "plain") => println!("plain text!"),
("text", _) => println!("structured text"),
_ => println!("not text"),
}
Case sensitivity
MediaType
and MediaTypeBuf
preserve the original string’s letter case;
values returned by accessor methods are not normalized.
Comparisons for MediaType
and MediaTypeBuf
are case-insensitive
except parameter values.
let lower: MediaTypeBuf = "text/plain; charset=UTF-8".parse().unwrap();
let upper: MediaTypeBuf = "TEXT/PLAIN; CHARSET=UTF-8".parse().unwrap();
assert_eq!(lower, upper);
assert_eq!(lower.to_string(), "text/plain; charset=UTF-8");
assert_eq!(upper.to_string(), "TEXT/PLAIN; CHARSET=UTF-8");
assert!(lower.ty() != upper.ty()); // "text" == "TEXT"
Modules
Structs
A referencing MediaType.
An owned and immutable MediaType.
A media-type name.
An iterator over the parameters.
A media-type parameter value.
Enums
Parsing error.