pub struct MediaType<'a> {
pub ty: Name<'a>,
pub subty: Name<'a>,
pub suffix: Option<Name<'a>>,
pub params: Cow<'a, [(Name<'a>, Value<'a>)]>,
}
Expand description
A borrowed media type.
use mediatype::{names::*, MediaType, Value, WriteParams};
let mut multipart = MediaType::new(MULTIPART, FORM_DATA);
let boundary = Value::new("dyEV84n7XNJ").unwrap();
multipart.set_param(BOUNDARY, boundary);
assert_eq!(
multipart.to_string(),
"multipart/form-data; boundary=dyEV84n7XNJ"
);
multipart.subty = RELATED;
assert_eq!(
multipart.to_string(),
"multipart/related; boundary=dyEV84n7XNJ"
);
const IMAGE_SVG: MediaType = MediaType::from_parts(IMAGE, SVG, Some(XML), &[]);
let svg = MediaType::parse("IMAGE/SVG+XML").unwrap();
assert_eq!(svg, IMAGE_SVG);
Fields§
§ty: Name<'a>
Top-level type.
subty: Name<'a>
Subtype.
suffix: Option<Name<'a>>
Optional suffix.
params: Cow<'a, [(Name<'a>, Value<'a>)]>
Parameters.
Implementations§
source§impl<'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>>,
params: &'a [(Name<'a>, Value<'a>)],
) -> Self
pub const fn from_parts( ty: Name<'a>, subty: Name<'a>, suffix: Option<Name<'a>>, params: &'a [(Name<'a>, Value<'a>)], ) -> Self
Constructs a MediaType
with an optional suffix and parameters.
const IMAGE_SVG: MediaType = MediaType::from_parts(IMAGE, SVG, Some(XML), &[(CHARSET, UTF_8)]);
assert_eq!(
IMAGE_SVG,
MediaType::parse("image/svg+xml; charset=UTF-8").unwrap()
);
Trait Implementations§
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 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§fn eq(&self, other: &&MediaTypeBuf) -> bool
fn eq(&self, other: &&MediaTypeBuf) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.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, 'b> PartialEq<MediaType<'b>> for MediaType<'a>
impl<'a, 'b> PartialEq<MediaType<'b>> for MediaType<'a>
source§impl<'a> PartialEq<MediaTypeBuf> for MediaType<'a>
impl<'a> PartialEq<MediaTypeBuf> for MediaType<'a>
source§fn eq(&self, other: &MediaTypeBuf) -> bool
fn eq(&self, other: &MediaTypeBuf) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl<'a> ReadParams for MediaType<'a>
impl<'a> ReadParams for MediaType<'a>
source§impl<'a> WriteParams<'a> for MediaType<'a>
impl<'a> WriteParams<'a> for MediaType<'a>
impl<'a> Eq for MediaType<'a>
Auto Trait Implementations§
impl<'a> Freeze for MediaType<'a>
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§
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)