Expand description

Parser and handler for MIME types.

This crate provides a type, Mime, which represents a MIME type as defined in RFC 2045 and RFC 2046. The aim of this library is to provide strongly typed MIME types that are an overall improvement over just repesenting MIME types as strings.

Example

use mr_mime::{Mime, constants};

// Parse a MIME type from a string.
let my_type = Mime::parse("text/html; charset=utf-8").unwrap();

// Get the "essence" of a MIME type.
let essence = my_type.essence();

// Compare it to a wide variety of constants.
assert_eq!(essence, constants::TEXT_HTML);

Features

This crate has the following features:

  • std, enabled by default, which enables the standard library. This is used to implement std::error::Error for ParseError.
  • alloc, enabled by default, which enables the alloc crate. This is used to implement hashing for MIME types. By default, the hashing algorithm tries to use stack space, but for strings longer than 128 bytes this can lead to a panic. The alloc feature ameliorates this by using the heap instead.

Modules

Constants for common MIME types and subtypes.

Structs

A MIME type.
The subtype name of a MIME type.
The suffix name of a MIME type.
The type name of a MIME type.

Enums

MIME type parsing error.