Struct mediatype::MediaTypeBuf
source · pub struct MediaTypeBuf { /* private fields */ }
Expand description
An owned and immutable media type.
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§
source§impl 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.
§Errors
Returns an error if the string fails to be parsed.
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§
source§impl AsRef<str> for MediaTypeBuf
impl AsRef<str> for MediaTypeBuf
source§impl Clone for MediaTypeBuf
impl Clone for MediaTypeBuf
source§fn clone(&self) -> MediaTypeBuf
fn clone(&self) -> MediaTypeBuf
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for MediaTypeBuf
impl Debug for MediaTypeBuf
source§impl Display for MediaTypeBuf
impl Display for MediaTypeBuf
source§impl From<&MediaType<'_>> for MediaTypeBuf
impl From<&MediaType<'_>> for MediaTypeBuf
source§impl<'a> From<&'a MediaTypeBuf> for MediaType<'a>
impl<'a> From<&'a MediaTypeBuf> for MediaType<'a>
source§fn from(t: &'a MediaTypeBuf) -> Self
fn from(t: &'a MediaTypeBuf) -> Self
Converts to this type from the input type.
source§impl From<MediaType<'_>> for MediaTypeBuf
impl From<MediaType<'_>> for MediaTypeBuf
source§impl FromStr for MediaTypeBuf
impl FromStr for MediaTypeBuf
source§impl Hash for MediaTypeBuf
impl Hash for MediaTypeBuf
source§impl PartialEq<&MediaType<'_>> for MediaTypeBuf
impl PartialEq<&MediaType<'_>> for MediaTypeBuf
source§impl<'a> PartialEq<&MediaTypeBuf> for MediaType<'a>
impl<'a> PartialEq<&MediaTypeBuf> for MediaType<'a>
source§impl PartialEq<MediaType<'_>> for &MediaTypeBuf
impl PartialEq<MediaType<'_>> for &MediaTypeBuf
source§impl PartialEq<MediaType<'_>> for MediaTypeBuf
impl PartialEq<MediaType<'_>> for MediaTypeBuf
source§impl<'a> PartialEq<MediaTypeBuf> for MediaType<'a>
impl<'a> PartialEq<MediaTypeBuf> for MediaType<'a>
source§impl PartialEq for MediaTypeBuf
impl PartialEq for MediaTypeBuf
source§impl ReadParams for MediaTypeBuf
impl ReadParams for MediaTypeBuf
impl Eq for MediaTypeBuf
Auto Trait Implementations§
impl Freeze for MediaTypeBuf
impl RefUnwindSafe for MediaTypeBuf
impl Send for MediaTypeBuf
impl Sync for MediaTypeBuf
impl Unpin for MediaTypeBuf
impl UnwindSafe for MediaTypeBuf
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)