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<T> PartialOrd for Mime<T>
impl<T> PartialOrd for Mime<T>
impl<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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.