pub struct MediaTypeBuf { /* private fields */ }
Expand description

An owned and immutable MediaType.

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

Constructs a MediaTypeBuf from a top-level type and a subtype.

Constructs a MediaTypeBuf with an optional suffix and parameters.

Constructs a MediaTypeBuf from String.

Unlike FromStr::from_str, this function takes the ownership of String instead of making a new copy.

Returns the top-level type.

Returns the subtype.

Returns the suffix.

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");

Returns the underlying string.

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"
);

Constructs a MediaType from self.

Trait Implementations

Converts this type into a shared reference of the (usually inferred) input type.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

The associated error which can be returned from parsing.

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Returns the parameters.

Gets the parameter value by its name. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.