Struct mediatype::MediaTypeBuf

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

An owned and immutable media type.

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§

source§

impl MediaTypeBuf

source

pub fn new(ty: Name<'_>, subty: Name<'_>) -> Self

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

source

pub fn from_parts( ty: Name<'_>, subty: Name<'_>, suffix: Option<Name<'_>>, params: &[(Name<'_>, Value<'_>)], ) -> Self

Constructs a MediaTypeBuf with an optional suffix and parameters.

source

pub fn from_string(s: String) -> Result<Self, MediaTypeError>

Constructs a MediaTypeBuf from String.

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

§Errors

Returns an error if the string fails to be parsed.

source

pub fn ty(&self) -> Name<'_>

Returns the top-level type.

source

pub fn subty(&self) -> Name<'_>

Returns the subtype.

source

pub fn suffix(&self) -> Option<Name<'_>>

Returns the suffix.

source

pub fn essence(&self) -> MediaType<'_>

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

pub const fn as_str(&self) -> &str

Returns the underlying string.

source

pub fn canonicalize(&self) -> Self

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

pub fn to_ref(&self) -> MediaType<'_>

Constructs a MediaType from self.

Trait Implementations§

source§

impl AsRef<str> for MediaTypeBuf

source§

fn as_ref(&self) -> &str

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

impl Clone for MediaTypeBuf

source§

fn clone(&self) -> MediaTypeBuf

Returns a copy 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 MediaTypeBuf

source§

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

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

impl Display for MediaTypeBuf

source§

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

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

impl From<&MediaType<'_>> for MediaTypeBuf

source§

fn from(t: &MediaType<'_>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a MediaTypeBuf> for MediaType<'a>

source§

fn from(t: &'a MediaTypeBuf) -> Self

Converts to this type from the input type.
source§

impl From<MediaType<'_>> for MediaTypeBuf

source§

fn from(t: MediaType<'_>) -> Self

Converts to this type from the input type.
source§

impl FromStr for MediaTypeBuf

§

type Err = MediaTypeError

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

fn from_str(s: &str) -> Result<Self, Self::Err>

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

impl Hash for MediaTypeBuf

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq<&MediaType<'_>> for MediaTypeBuf

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialEq<&MediaTypeBuf> for MediaType<'a>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<MediaType<'_>> for &MediaTypeBuf

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<MediaType<'_>> for MediaTypeBuf

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialEq<MediaTypeBuf> for MediaType<'a>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for MediaTypeBuf

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl ReadParams for MediaTypeBuf

source§

fn params(&self) -> Params<'_>

Returns the parameters.
source§

fn get_param(&self, name: Name<'_>) -> Option<Value<'_>>

Gets the parameter value by its name. Read more
source§

impl Eq for MediaTypeBuf

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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

§

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§

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

§

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

§

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.