Skip to content

Releases: hyperium/mime

v0.3.0

28 Dec 21:49
Compare
Choose a tag to compare

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 the std::fmt machinery.

    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, like mime::TEXT_PLAIN, or parse a custom string into a Mime, like "application/vnd.github.api.v3+json".parse(). No more importing 5 different types or passing empty Vecs.

    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 SubLevel variant?). 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 Mime in 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, Mime and its components can be easily compared against &str.

    assert_eq!(mime::TEXT_PLAIN, "text/plain");