Crate mediatype

source
Expand description

This crate provides two media type 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, @generated in tests/codegen.rs
  • Predefined parameter values, @generated in tests/codegen.rs

Macros§

Structs§

Enums§

Traits§