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
sourceimpl<T> Ord for Mime<T>where
T: Ord + AsRef<[(Attr, Value)]>,
impl<T> Ord for Mime<T>where
T: Ord + AsRef<[(Attr, Value)]>,
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<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)]>,
sourceimpl<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)]>,
sourcefn partial_cmp(&self, other: &Mime<T>) -> Option<Ordering>
fn partial_cmp(&self, other: &Mime<T>) -> Option<Ordering>
1.0.0 · sourcefn 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>where
T: Eq + AsRef<[(Attr, Value)]>,
impl<T> StructuralEq for Mime<T>where
T: AsRef<[(Attr, Value)]>,
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more