Struct iron::mime::Mime [] [src]

pub struct Mime<T = Vec<(Attr, Value)>> where T: AsRef<[(Attr, Value)]>(pub TopLevel, pub SubLevel, pub T);

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!"),
    _ => ()
}

Methods

impl<P> Mime<P> where P: AsRef<[(Attr, Value)]>

fn get_param<A>(&self, attr: A) -> Option<&Value> where A: PartialEq<Attr>

Trait Implementations

impl<LHS, RHS> PartialEq<Mime<RHS>> for Mime<LHS> where LHS: AsRef<[(Attr, Value)]>, RHS: AsRef<[(Attr, Value)]>

fn eq(&self, other: &Mime<RHS>) -> bool

fn ne(&self, other: &Rhs) -> bool

impl<T> Display for Mime<T> where T: AsRef<[(Attr, Value)]>

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

impl FromStr for Mime<Vec<(Attr, Value)>>

type Err = ()

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

impl Serialize for Mime<Vec<(Attr, Value)>>

fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer

impl Deserialize for Mime<Vec<(Attr, Value)>>

fn deserialize<D>(deserializer: &mut D) -> Result<Mime<Vec<(Attr, Value)>>, D::Error> where D: Deserializer

impl Modifier<Response> for Mime

fn modify(self, res: &mut Response)

Derived Implementations

impl<T> Debug for Mime<T> where T: AsRef<[(Attr, Value)]> + Debug

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

impl<T> Clone for Mime<T> where T: Clone + AsRef<[(Attr, Value)]>

fn clone(&self) -> Mime<T>

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