Releases: hyperium/mime
v0.3.0
Changed from several open-ended enums to an opaque Mime struct.
-
It should be fast. The improvement here is that the full text is stored in a single buffer. In the previous versions, being a bunch of internal enums, it was quite slow to use
fmt::Display. Writing a single buffer reduces the overhead of thestd::fmtmachinery.Comparisons with constants is near instant. Comparing with parsed
Mimes is slightly slower, but there is also room to add optimizations which I've skipped in order to get this our the door. -
It should be easy to create a
Mime. In this design, you can use one of the common constants, likemime::TEXT_PLAIN, or parse a custom string into aMime, like"application/vnd.github.api.v3+json".parse(). No more importing 5 different types or passing emptyVecs.With macros 2.0, it will be possible to make a macro that can parse the text at compile time, allowing custom constant
Mimes. -
It should be extensible. As a bunch of enums, adding new variants was technically a breaking change (though who would match on every
SubLevelvariant?). By using constants, new ones can be added without breaking anyone. -
Knowledge of suffixes. You can check the suffix, such as in
image/svg+xml. -
Comparing is still easy. You can still compare the various components of a
Mimein a match. This works perfectly fine:match (mime.type_(), mime.subtype()) { (mime::TEXT, mime::PLAIN) => println!("plain text"), (mime::TEXT, _) => println!("structured text"), _ => println!("not text"), }
Additionally,
Mimeand its components can be easily compared against&str.assert_eq!(mime::TEXT_PLAIN, "text/plain");