pub struct Mime<T = Vec<(Attr, Value)>>(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>
impl<T> Ord for Mime<T>
source§impl<LHS, RHS> PartialEq<Mime<RHS>> for Mime<LHS>
impl<LHS, RHS> PartialEq<Mime<RHS>> for Mime<LHS>
source§impl<T> PartialOrd for Mime<T>
impl<T> PartialOrd for Mime<T>
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 moreimpl<T> Eq for Mime<T>
Auto Trait Implementations§
impl<T> Freeze for Mime<T>where
T: Freeze,
impl<T> RefUnwindSafe for Mime<T>where
T: RefUnwindSafe,
impl<T> Send for Mime<T>where
T: Send,
impl<T> Sync for Mime<T>where
T: Sync,
impl<T> Unpin for Mime<T>where
T: Unpin,
impl<T> UnwindSafe for Mime<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.