pub struct Mime {
pub(crate) source: Source,
pub(crate) slash: usize,
pub(crate) plus: Option<usize>,
pub(crate) params: ParamSource,
}
Expand description
A parsed mime or media type.
Fields§
§source: Source
§slash: usize
§plus: Option<usize>
§params: ParamSource
Implementations§
source§impl Mime
impl Mime
sourcepub fn type_(&self) -> Name<'_>
pub fn type_(&self) -> Name<'_>
Get the top level media type for this Mime
.
§Example
let mime = mime::TEXT_PLAIN;
assert_eq!(mime.type_(), "text");
assert_eq!(mime.type_(), mime::TEXT);
sourcepub fn subtype(&self) -> Name<'_>
pub fn subtype(&self) -> Name<'_>
Get the subtype of this Mime
.
§Example
let mime = mime::TEXT_PLAIN;
assert_eq!(mime.subtype(), "plain");
assert_eq!(mime.subtype(), mime::PLAIN);
sourcepub fn suffix(&self) -> Option<Name<'_>>
pub fn suffix(&self) -> Option<Name<'_>>
Get an optional +suffix for this Mime
.
§Example
let svg = "image/svg+xml".parse::<mime::Mime>().unwrap();
assert_eq!(svg.suffix(), Some(mime::XML));
assert_eq!(svg.suffix().unwrap(), "xml");
assert!(mime::TEXT_PLAIN.suffix().is_none());
sourcepub fn get_param<'a, N>(&'a self, attr: N) -> Option<Name<'a>>
pub fn get_param<'a, N>(&'a self, attr: N) -> Option<Name<'a>>
Look up a parameter by name.
§Example
let mime = mime::TEXT_PLAIN_UTF_8;
assert_eq!(mime.get_param(mime::CHARSET), Some(mime::UTF_8));
assert_eq!(mime.get_param("charset").unwrap(), "utf-8");
assert!(mime.get_param("boundary").is_none());
let mime = "multipart/form-data; boundary=ABCDEFG".parse::<mime::Mime>().unwrap();
assert_eq!(mime.get_param(mime::BOUNDARY).unwrap(), "ABCDEFG");
sourcepub fn essence_str(&self) -> &str
pub fn essence_str(&self) -> &str
Return a &str
of the Mime’s “essence”.
pub(crate) fn semicolon(&self) -> Option<usize>
pub(crate) fn atom(&self) -> u8
Trait Implementations§
source§impl Ord for Mime
impl Ord for Mime
source§impl PartialEq for Mime
impl PartialEq for Mime
source§impl PartialOrd for Mime
impl PartialOrd for Mime
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 Eq for Mime
Auto Trait Implementations§
impl Freeze for Mime
impl RefUnwindSafe for Mime
impl Send for Mime
impl Sync for Mime
impl Unpin for Mime
impl UnwindSafe for Mime
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