pub struct Mime { /* private fields */ }
Expand description
An IANA media type.
use http_types::Mime;
use std::str::FromStr;
let mime = Mime::from_str("text/html;charset=utf-8").unwrap();
assert_eq!(mime.essence(), "text/html");
assert_eq!(mime.param("charset").unwrap(), "utf-8");
Implementations§
Source§impl Mime
impl Mime
Sourcepub fn from_extension(extension: impl AsRef<str>) -> Option<Mime>
pub fn from_extension(extension: impl AsRef<str>) -> Option<Mime>
Guess the mime type from a file extension
Sourcepub fn basetype(&self) -> &str
pub fn basetype(&self) -> &str
Access the Mime’s type
value.
According to the spec this method should be named type
, but that’s a reserved keyword in
Rust so hence prefix with base
instead.
Sourcepub fn param(&self, name: impl Into<ParamName>) -> Option<&ParamValue>
pub fn param(&self, name: impl Into<ParamName>) -> Option<&ParamValue>
Get a reference to a param.
Sourcepub fn remove_param(&mut self, name: impl Into<ParamName>) -> Option<ParamValue>
pub fn remove_param(&mut self, name: impl Into<ParamName>) -> Option<ParamValue>
Remove a param from the set. Returns the ParamValue
if it was contained within the set.
Trait Implementations§
Source§impl From<&Mime> for HeaderValue
impl From<&Mime> for HeaderValue
Source§fn from(mime: &Mime) -> HeaderValue
fn from(mime: &Mime) -> HeaderValue
Converts to this type from the input type.
Source§impl From<MediaTypeProposal> for Mime
impl From<MediaTypeProposal> for Mime
Source§fn from(accept: MediaTypeProposal) -> Mime
fn from(accept: MediaTypeProposal) -> Mime
Converts to this type from the input type.
Source§impl From<Mime> for HeaderValue
impl From<Mime> for HeaderValue
Source§fn from(mime: Mime) -> HeaderValue
fn from(mime: Mime) -> HeaderValue
Converts to this type from the input type.
Source§impl ToHeaderValues for Mime
impl ToHeaderValues for Mime
Source§type Iter = IntoIter<HeaderValue>
type Iter = IntoIter<HeaderValue>
Returned iterator over header values which this type may correspond to.
Source§fn to_header_values(&self) -> Result<<Mime as ToHeaderValues>::Iter, Error>
fn to_header_values(&self) -> Result<<Mime as ToHeaderValues>::Iter, Error>
Converts this object to an iterator of resolved
HeaderValues
.impl Eq for Mime
impl StructuralPartialEq 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