worker_route::http

Struct ContentType

Source
pub struct ContentType(/* private fields */);
Expand description

Content-Type header, defined in RFC 9110 §8.3.

Implementations§

Source§

impl ContentType

Source

pub const fn form_url_encoded() -> Self

Content-Type: application/x-www-form-urlencoded header.

Source

pub const fn html_utf8() -> Self

Content-Type: text/html; charset=utf-8 header.

Source

pub const fn html() -> Self

Content-Type: text/html header.

Source

pub const fn jpeg() -> Self

Content-Type: image/jpeg header.

Source

pub const fn json() -> Self

Content-Type: application/json header.

Source

pub const fn octet_stream() -> Self

Content-Type: application/octet-stream header.

Source

pub const fn plaintext_utf8() -> Self

Content-Type: text/plain; charset=utf-8 header.

Source

pub const fn plaintext() -> Self

Content-Type: text/plain header.

Source

pub const fn png() -> Self

Content-Type: image/png header.

Source

pub const fn xml() -> Self

Content-Type: text/xml header.

Source

pub fn as_str(&self) -> &str

Returns a &str of the Mime’s

Source

pub fn get_mime(&self) -> &Mime

Returns self’ Mime

Source

pub fn char_set(&self) -> Option<&'static str>

Returns self’s charset if there’s any.

Source

pub const fn to_header_value(&self) -> HeaderValue

Returns a HeaderValue from self’s top level media type with its subtype and charset if there’s any.

§Example
use worker_route::http::ContentType;

let html_utf8 = ContentType::html_utf8();
let header_value = html_utf8.to_header_value();

assert_eq!(header_value, "text/html; charset=utf-8");

Trait Implementations§

Source§

impl Debug for ContentType

Source§

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

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

impl Display for ContentType

Source§

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

Formats the value using the given formatter. Read more

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> 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> 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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T