Expand description

This crate provides two MediaType structs: MediaType and MediaTypeBuf.

  • MediaType does not copy data during parsing and borrows the original string. It is also const-constructible.
  • MediaTypeBuf is an owned and immutable version of MediaType.
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);

Letter case handling

MediaType and MediaTypeBuf preserve the original string’s letter case. Comparisons for MediaType, MediaTypeBuf and Name 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.as_str(), "text/plain; charset=UTF-8");
assert_eq!(upper.as_str(), "TEXT/PLAIN; CHARSET=UTF-8");
assert_eq!(lower, upper);
assert_eq!(lower.ty(), "Text");
assert_eq!(upper.subty(), "Plain");

Modules

Predefined names.

Predefined parameter values.

Macros

Convenient macro to construct a MediaType.

Structs

A borrowed MediaType.

An owned and immutable MediaType.

A media-type name.

An iterator over the parameters.

A media-type parameter value.

Enums

Media-type format error.

Traits

A trait for getting parameter values.

A trait for mutating parameter values.