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

Indicate the media type of a resource’s content.

MDN Documentation

Specifications

Examples

use http_types::content::ContentType;
use http_types::{Response, Mime};
use std::str::FromStr;

let content_type = ContentType::new("text/*");

let mut res = Response::new(200);
content_type.apply(&mut res);

let content_type = ContentType::from_headers(res)?.unwrap();
assert_eq!(content_type.value(), format!("{}", Mime::from_str("text/*")?).as_str());

Implementations

Create a new instance.

Create a new instance from headers.

Content-Type headers can provide both full and partial URLs. In order to always return fully qualified URLs, a base URL must be passed to reference the current environment. In HTTP/1.1 and above this value can always be determined from the request.

Sets the header.

Get the HeaderName.

Get the HeaderValue.

Trait Implementations

Formats the value using the given formatter. Read more

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 !=.

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.

Should always be Self

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.