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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)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.