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

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

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

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

Constructs a MediaType from str without copying the string.

Returns a MediaType without parameters.

const IMAGE_SVG: MediaType = MediaType::from_parts(IMAGE, SVG, Some(XML), &[(CHARSET, UTF_8)]);
assert_eq!(
    IMAGE_SVG.essence(),
    MediaType::parse("image/svg+xml").unwrap()
);

Trait Implementations

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.

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

Sets a parameter value. Read more

Removes all parameters with the name.

Removes all parameters.

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.