MediaType

Struct MediaType 

Source
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

Source

pub fn wildcard() -> MediaType

Creates the wildcard media type */*.

Source

pub fn wildcard_subtype(type_: Type) -> MediaType

Creates a media type with only a concrete type and no subtype like image/*.

Source

pub fn new<A>(type_: Type, tree: Tree, subtype: A) -> MediaType
where A: Into<Cow<'static, str>>,

Creates a new media type.

Source

pub 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>>,

Creates a new media type with suffix.

Source

pub fn tree(&self) -> Option<&Tree>

Accesses the tree component of the subtype.

Source

pub fn sub(&self) -> Option<&str>

Accesses the sub component of the subtype containing the resource type.

Source

pub fn suffix(&self) -> Option<&str>

Accesses the suffix of the type.

Source

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.

Source

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).

Source

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.

Source

pub fn set_charset_utf8(&mut self) -> Option<Cow<'static, str>>

Sets the charset to UTF-8.

Source

pub fn eq_mime_portion(&self, other: &MediaType) -> bool

Compares the mime type portion (the media type without parameters) of two media types.

Source

pub fn ne_mime_portion(&self, other: &MediaType) -> bool

Returns true if the mime type portions differ, strict inverse of eq_mime_portion().

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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 Clone for MediaType

Source§

fn clone(&self) -> MediaType

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MediaType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MediaType

Source§

fn default() -> MediaType

Returns the “default value” for a type. Read more
Source§

impl Display for MediaType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for MediaType

top-level type name / [ tree. ] subtype name [ +suffix ] [ ; parameters ]

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<MediaType>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for MediaType

Source§

fn eq(&self, other: &MediaType) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for MediaType

Source§

impl StructuralPartialEq for MediaType

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.