Struct mediatype::MediaTypeBuf
source · [−]pub struct MediaTypeBuf { /* private fields */ }
Expand description
An owned and immutable MediaType.
use mediatype::{names::*, values::*, MediaType, MediaTypeBuf, ReadParams};
let text_plain: MediaTypeBuf = "text/plain; charset=UTF-8".parse().unwrap();
assert_eq!(text_plain.get_param(CHARSET).unwrap(), UTF_8);
let mut text_markdown: MediaType = text_plain.to_ref();
text_markdown.subty = MARKDOWN;
assert_eq!(text_markdown.to_string(), "text/markdown; charset=UTF-8");
Implementations
sourceimpl MediaTypeBuf
impl MediaTypeBuf
sourcepub fn new(ty: Name<'_>, subty: Name<'_>) -> Self
pub fn new(ty: Name<'_>, subty: Name<'_>) -> Self
Constructs a MediaTypeBuf
from a top-level type and a subtype.
sourcepub fn from_parts(
ty: Name<'_>,
subty: Name<'_>,
suffix: Option<Name<'_>>,
params: &[(Name<'_>, Value<'_>)]
) -> Self
pub fn from_parts(
ty: Name<'_>,
subty: Name<'_>,
suffix: Option<Name<'_>>,
params: &[(Name<'_>, Value<'_>)]
) -> Self
Constructs a MediaTypeBuf
with an optional suffix and parameters.
sourcepub fn from_string(s: String) -> Result<Self, MediaTypeError>
pub fn from_string(s: String) -> Result<Self, MediaTypeError>
Constructs a MediaTypeBuf
from String
.
Unlike FromStr::from_str
, this function takes the ownership of String
instead of making a new copy.
sourcepub fn essence(&self) -> MediaType<'_>
pub fn essence(&self) -> MediaType<'_>
Returns a MediaType
without parameters.
let media_type: MediaTypeBuf = "image/svg+xml; charset=UTF-8".parse().unwrap();
assert_eq!(media_type.essence().to_string(), "image/svg+xml");
sourcepub fn canonicalize(&self) -> Self
pub fn canonicalize(&self) -> Self
Returns the canonicalized MediaTypeBuf
.
All strings except parameter values will be converted to lowercase.
let media_type: MediaTypeBuf = "IMAGE/SVG+XML; CHARSET=UTF-8; ".parse().unwrap();
assert_eq!(
media_type.canonicalize().to_string(),
"image/svg+xml; charset=UTF-8"
);
Trait Implementations
sourceimpl Clone for MediaTypeBuf
impl Clone for MediaTypeBuf
sourcefn clone(&self) -> MediaTypeBuf
fn clone(&self) -> MediaTypeBuf
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for MediaTypeBuf
impl Debug for MediaTypeBuf
sourceimpl<'de> Deserialize<'de> for MediaTypeBuf
impl<'de> Deserialize<'de> for MediaTypeBuf
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 Display for MediaTypeBuf
impl Display for MediaTypeBuf
sourceimpl From<&'_ MediaType<'_>> for MediaTypeBuf
impl From<&'_ MediaType<'_>> for MediaTypeBuf
sourceimpl<'a> From<&'a MediaTypeBuf> for MediaType<'a>
impl<'a> From<&'a MediaTypeBuf> for MediaType<'a>
sourcefn from(t: &'a MediaTypeBuf) -> Self
fn from(t: &'a MediaTypeBuf) -> Self
Performs the conversion.
sourceimpl From<MediaType<'_>> for MediaTypeBuf
impl From<MediaType<'_>> for MediaTypeBuf
sourceimpl FromStr for MediaTypeBuf
impl FromStr for MediaTypeBuf
sourceimpl PartialEq<&'_ MediaType<'_>> for MediaTypeBuf
impl PartialEq<&'_ MediaType<'_>> for MediaTypeBuf
sourceimpl<'a> PartialEq<&'_ MediaTypeBuf> for MediaType<'a>
impl<'a> PartialEq<&'_ MediaTypeBuf> for MediaType<'a>
sourceimpl PartialEq<MediaType<'_>> for MediaTypeBuf
impl PartialEq<MediaType<'_>> for MediaTypeBuf
sourceimpl<'a> PartialEq<MediaTypeBuf> for MediaType<'a>
impl<'a> PartialEq<MediaTypeBuf> for MediaType<'a>
sourceimpl PartialEq<MediaTypeBuf> for MediaTypeBuf
impl PartialEq<MediaTypeBuf> for MediaTypeBuf
sourceimpl ReadParams for MediaTypeBuf
impl ReadParams for MediaTypeBuf
sourceimpl Serialize for MediaTypeBuf
impl Serialize for MediaTypeBuf
impl Eq for MediaTypeBuf
Auto Trait Implementations
impl RefUnwindSafe for MediaTypeBuf
impl Send for MediaTypeBuf
impl Sync for MediaTypeBuf
impl Unpin for MediaTypeBuf
impl UnwindSafe for MediaTypeBuf
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