pub struct Mime<T = Vec<(Attr, Value), Global>>(pub TopLevel, pub SubLevel, pub T)
where
T: AsRef<[(Attr, Value)]>;
Expand description
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!"),
_ => ()
}
Tuple Fields§
§0: TopLevel
§1: SubLevel
§2: T
Implementations§
Trait Implementations§
source§impl<T> Ord for Mime<T>where
T: Ord + AsRef<[(Attr, Value)]>,
impl<T> Ord for Mime<T>where
T: Ord + AsRef<[(Attr, Value)]>,
source§impl<LHS, RHS> PartialEq<Mime<RHS>> for Mime<LHS>where
LHS: AsRef<[(Attr, Value)]>,
RHS: AsRef<[(Attr, Value)]>,
impl<LHS, RHS> PartialEq<Mime<RHS>> for Mime<LHS>where
LHS: AsRef<[(Attr, Value)]>,
RHS: AsRef<[(Attr, Value)]>,
source§impl<T> PartialOrd<Mime<T>> for Mime<T>where
T: PartialOrd<T> + AsRef<[(Attr, Value)]>,
impl<T> PartialOrd<Mime<T>> for Mime<T>where
T: PartialOrd<T> + AsRef<[(Attr, Value)]>,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more