pub struct MediaType<'a> { /* private fields */ }
Expand description
A parsed MediaType.
Implementations
sourceimpl<'a> MediaType<'a>
impl<'a> MediaType<'a>
sourcepub const fn new(ty: Name<'a>, subty: Name<'a>) -> Self
pub const fn new(ty: Name<'a>, subty: Name<'a>) -> Self
Constructs a MediaType
from a top-level type and a subtype.
const IMAGE_PNG: MediaType = MediaType::new(IMAGE, PNG);
assert_eq!(IMAGE_PNG, MediaType::parse("image/png").unwrap());
sourcepub const fn from_parts(
ty: Name<'a>,
subty: Name<'a>,
suffix: Option<Name<'a>>,
param: Option<&'a [(Name<'a>, Value<'a>); 1]>
) -> Self
pub const fn from_parts(
ty: Name<'a>,
subty: Name<'a>,
suffix: Option<Name<'a>>,
param: Option<&'a [(Name<'a>, Value<'a>); 1]>
) -> Self
Constructs a MediaType
with an optional suffix and parameters.
This function accepts only one parameter because key duplication is not detectable at compile-time.
const IMAGE_SVG: MediaType =
MediaType::from_parts(IMAGE, SVG, Some(XML), Some(&[(CHARSET, UTF_8)]));
assert_eq!(
IMAGE_SVG,
MediaType::parse("image/svg+xml; charset=UTF-8").unwrap()
);
sourcepub fn parse<'s: 'a>(s: &'s str) -> Result<Self, ParseError>
pub fn parse<'s: 'a>(s: &'s str) -> Result<Self, ParseError>
Constructs a MediaType
from str
.
sourcepub fn set_suffix<'s: 'a>(&mut self, suffix: &'s Option<Name<'_>>)
pub fn set_suffix<'s: 'a>(&mut self, suffix: &'s Option<Name<'_>>)
Sets the suffix.
sourcepub fn params(&self) -> Params<'_>ⓘNotable traits for Params<'a>impl<'a> Iterator for Params<'a> type Item = (&'a str, &'a str);
pub fn params(&self) -> Params<'_>ⓘNotable traits for Params<'a>impl<'a> Iterator for Params<'a> type Item = (&'a str, &'a str);
Returns an iterator over the parameters.
The parameters are alphabetically sorted by their keys.
sourcepub fn get_param(&self, key: &Name<'_>) -> Option<&str>
pub fn get_param(&self, key: &Name<'_>) -> Option<&str>
Gets the parameter value by its key.
The key is case-insensitive.
sourcepub fn set_param<'k: 'a, 'v: 'a>(
&mut self,
key: &'k Name<'_>,
value: &'v Value<'_>
) -> Option<&str>
pub fn set_param<'k: 'a, 'v: 'a>(
&mut self,
key: &'k Name<'_>,
value: &'v Value<'_>
) -> Option<&str>
Sets a parameter value.
If the parameter is already set, replaces it with a new value and returns the old value. The key is case-insensitive.
sourcepub fn remove_param(&mut self, key: &Name<'_>) -> Option<&str>
pub fn remove_param(&mut self, key: &Name<'_>) -> Option<&str>
Removes and returns a parameter value by its key.
The key is case-insensitive.
Trait Implementations
sourceimpl<'de> Deserialize<'de> for MediaType<'de>
impl<'de> Deserialize<'de> for MediaType<'de>
sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<'a> Ord for MediaType<'a>
impl<'a> Ord for MediaType<'a>
sourceimpl PartialEq<MediaType<'_>> for MediaTypeBuf
impl PartialEq<MediaType<'_>> for MediaTypeBuf
sourceimpl PartialOrd<MediaType<'_>> for MediaTypeBuf
impl PartialOrd<MediaType<'_>> for MediaTypeBuf
sourcefn partial_cmp(&self, other: &MediaType<'_>) -> Option<Ordering>
fn partial_cmp(&self, other: &MediaType<'_>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
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 more
sourceimpl<'a> PartialOrd<MediaType<'a>> for MediaType<'a>
impl<'a> PartialOrd<MediaType<'a>> for MediaType<'a>
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
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 more
impl<'a> Eq for MediaType<'a>
Auto Trait Implementations
impl<'a> RefUnwindSafe for MediaType<'a>
impl<'a> Send for MediaType<'a>
impl<'a> Sync for MediaType<'a>
impl<'a> Unpin for MediaType<'a>
impl<'a> UnwindSafe for MediaType<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more