Struct hyper::mime::Mime [-] [+] [src]

pub struct Mime(pub TopLevel, pub SubLevel, pub Vec<(Attr, Value)>);

Mime, or Media Type. Encapsulates common registers types.

Consider that a traditional mime type contains a "top level type", a "sub level type", and 0-N "parameters". And they're all strings. Strings everywhere. Strings mean typos. Rust has type safety. We should use types!

So, Mime bundles together this data into types so the compiler can catch your typos.

This improves things so you use match without Strings:

use mime::{Mime, TopLevel, SubLevel};

let mime: Mime = "application/json".parse().unwrap();

match mime {
    Mime(TopLevel::Application, SubLevel::Json, _) => println!("matched json!"),
    _ => ()
}

Trait Implementations

impl Display for Mime

fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>

impl FromStr for Mime

type Err = ()

fn from_str(raw: &str) -> Result<Mime, ()>

Derived Implementations

impl Debug for Mime

fn fmt(&self, __arg_0: &mut Formatter) -> Result<(), Error>

impl PartialEq<Mime> for Mime

fn eq(&self, __arg_0: &Mime) -> bool

fn ne(&self, __arg_0: &Mime) -> bool

impl Clone for Mime

fn clone(&self) -> Mime

fn clone_from(&mut self, source: &Self)