pub struct MediaType {
pub type_: Option<Type>,
pub subtype: Option<(Tree, Cow<'static, str>, Option<Cow<'static, str>>)>,
pub parameters: HashMap<Cow<'static, str>, Cow<'static, str>>,
}Expand description
A Media Type commonly used to describe the contents of a resource.
Fields§
§type_: Option<Type>The top-level type or None to match all types.
subtype: Option<(Tree, Cow<'static, str>, Option<Cow<'static, str>>)>A subtype describing the concrete file format. The first element of the tuple is the registration tree, it describes if they are registered by a standards organization, a vendor, or if they are only for private use. The second tuple element is the subtype, it describes the resource. The last part is the suffix it tells how the file was encoded common values are “xml” and “json”.
parameters: HashMap<Cow<'static, str>, Cow<'static, str>>Media types can contain optional parameters for example for charsets or video codes.
Implementations§
Source§impl MediaType
impl MediaType
Sourcepub fn wildcard_subtype(type_: Type) -> MediaType
pub fn wildcard_subtype(type_: Type) -> MediaType
Creates a media type with only a concrete type and no subtype like image/*.
Sourcepub fn new_with_suffix<A, B>(
type_: Type,
tree: Tree,
subtype: A,
suffix: B,
) -> MediaType
pub fn new_with_suffix<A, B>( type_: Type, tree: Tree, subtype: A, suffix: B, ) -> MediaType
Creates a new media type with suffix.
Sourcepub fn sub(&self) -> Option<&str>
pub fn sub(&self) -> Option<&str>
Accesses the sub component of the subtype containing the resource type.
Sourcepub fn boundary(&self) -> Result<&str>
pub fn boundary(&self) -> Result<&str>
The boundary parameter is used to separate different blocks of multipart resources.
It is defined in RFC2046 - Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types #5.1. Multipart Media Type.
Sourcepub fn charset(&self) -> Result<Charset>
pub fn charset(&self) -> Result<Charset>
The charset parameter is defined for text/* types, it carries information about the
charset.
The relevant RFCs are RFC2046 - Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types #4.1.2. Charset Parameter and [RFC6657 - Update to MIME regarding “charset” Parameter Handling in Textual Media Types] (https://tools.ietf.org/html/rfc6657).
Sourcepub fn set_charset(&mut self, charset: Charset) -> Option<Cow<'static, str>>
pub fn set_charset(&mut self, charset: Charset) -> Option<Cow<'static, str>>
Sets the charset parameter to the given charset and returns the old value if present.
Sourcepub fn set_charset_utf8(&mut self) -> Option<Cow<'static, str>>
pub fn set_charset_utf8(&mut self) -> Option<Cow<'static, str>>
Sets the charset to UTF-8.
Sourcepub fn eq_mime_portion(&self, other: &MediaType) -> bool
pub fn eq_mime_portion(&self, other: &MediaType) -> bool
Compares the mime type portion (the media type without parameters) of two media types.
Sourcepub fn ne_mime_portion(&self, other: &MediaType) -> bool
pub fn ne_mime_portion(&self, other: &MediaType) -> bool
Returns true if the mime type portions differ, strict inverse of eq_mime_portion().
Sourcepub fn is_image_type(&self) -> bool
pub fn is_image_type(&self) -> bool
Checks if the media type is an image type.
Implements the [MIME Sniffing standard] (https://mimesniff.spec.whatwg.org/#mime-type-groups) for MIME type groups.
Sourcepub fn is_audio_or_video_type(&self) -> bool
pub fn is_audio_or_video_type(&self) -> bool
Checks if the media type is an audio or video type.
Implements the [MIME Sniffing standard] (https://mimesniff.spec.whatwg.org/#mime-type-groups) for MIME type groups.
Sourcepub fn is_font_type(&self) -> bool
pub fn is_font_type(&self) -> bool
Checks if the media type is a font type.
Implements the [MIME Sniffing standard] (https://mimesniff.spec.whatwg.org/#mime-type-groups) for MIME type groups.
Sourcepub fn is_zip_based_type(&self) -> bool
pub fn is_zip_based_type(&self) -> bool
Checks if the media type is a zip based type.
Implements the [MIME Sniffing standard] (https://mimesniff.spec.whatwg.org/#mime-type-groups) for MIME type groups.
Sourcepub fn is_archive_type(&self) -> bool
pub fn is_archive_type(&self) -> bool
Checks if the media type is an archive type.
Implements the [MIME Sniffing standard] (https://mimesniff.spec.whatwg.org/#mime-type-groups) for MIME type groups.
Sourcepub fn is_xml_type(&self) -> bool
pub fn is_xml_type(&self) -> bool
Checks if the media type is an XML type.
Implements the [MIME Sniffing standard] (https://mimesniff.spec.whatwg.org/#mime-type-groups) for MIME type groups.
Sourcepub fn is_scriptable_mime_type(&self) -> bool
pub fn is_scriptable_mime_type(&self) -> bool
Checks if the media type is a scriptable type, HTML or PDF.
Implements the [MIME Sniffing standard] (https://mimesniff.spec.whatwg.org/#mime-type-groups) for MIME type groups.
Trait Implementations§
Source§impl FromStr for MediaType
top-level type name / [ tree. ] subtype name [ +suffix ] [ ; parameters ]
impl FromStr for MediaType
top-level type name / [ tree. ] subtype name [ +suffix ] [ ; parameters ]