Struct media_types::MediaType
[−]
[src]
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>>, }
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.
Methods
impl MediaType
[src]
fn wildcard() -> MediaType
Creates the wildcard media type */*
.
fn wildcard_subtype(type_: Type) -> MediaType
Creates a media type with only a concrete type and no subtype like image/*
.
fn new<A>(type_: Type, tree: Tree, subtype: A) -> MediaType where
A: Into<Cow<'static, str>>,
A: Into<Cow<'static, str>>,
Creates a new media type.
fn new_with_suffix<A, B>(
type_: Type,
tree: Tree,
subtype: A,
suffix: B
) -> MediaType where
A: Into<Cow<'static, str>>,
B: Into<Cow<'static, str>>,
type_: Type,
tree: Tree,
subtype: A,
suffix: B
) -> MediaType where
A: Into<Cow<'static, str>>,
B: Into<Cow<'static, str>>,
Creates a new media type with suffix.
fn tree(&self) -> Option<&Tree>
Accesses the tree component of the subtype.
fn sub(&self) -> Option<&str>
Accesses the sub component of the subtype containing the resource type.
fn suffix(&self) -> Option<&str>
Accesses the suffix of the type.
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.
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.
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.
fn set_charset_utf8(&mut self) -> Option<Cow<'static, str>>
Sets the charset to UTF-8.
fn eq_mime_portion(&self, other: &MediaType) -> bool
Compares the mime type portion (the media type without parameters) of two media types.
fn ne_mime_portion(&self, other: &MediaType) -> bool
Returns true if the mime type portions differ, strict inverse of eq_mime_portion()
.
fn is_image_type(&self) -> bool
Checks if the media type is an image type.
Implements the MIME Sniffing standard for MIME type groups.
fn is_audio_or_video_type(&self) -> bool
Checks if the media type is an audio or video type.
Implements the MIME Sniffing standard for MIME type groups.
fn is_font_type(&self) -> bool
Checks if the media type is a font type.
Implements the MIME Sniffing standard for MIME type groups.
fn is_zip_based_type(&self) -> bool
Checks if the media type is a zip based type.
Implements the MIME Sniffing standard for MIME type groups.
fn is_archive_type(&self) -> bool
Checks if the media type is an archive type.
Implements the MIME Sniffing standard for MIME type groups.
fn is_xml_type(&self) -> bool
Checks if the media type is an XML type.
Implements the MIME Sniffing standard for MIME type groups.
fn is_scriptable_mime_type(&self) -> bool
Checks if the media type is a scriptable type, HTML or PDF.
Implements the MIME Sniffing standard for MIME type groups.
Trait Implementations
impl Clone for MediaType
[src]
fn clone(&self) -> MediaType
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Debug for MediaType
[src]
impl Default for MediaType
[src]
impl Eq for MediaType
[src]
impl PartialEq for MediaType
[src]
fn eq(&self, __arg_0: &MediaType) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &MediaType) -> bool
This method tests for !=
.
impl FromStr for MediaType
[src]
top-level type name / [ tree. ] subtype name [ +suffix ] [ ; parameters ]
type Err = Error
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<MediaType>
Parses a string s
to return a value of this type. Read more