#[non_exhaustive]pub enum ContentType {
Json,
Form,
MsgPack,
Bincode,
Bitcode,
Yaml,
Toml,
}
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Implementations§
Source§impl ContentType
impl ContentType
Sourcepub fn from_header(header: &HeaderValue) -> Option<Self>
pub fn from_header(header: &HeaderValue) -> Option<Self>
Attempts to parse the given HeaderValue
into a ContentType
by treating it as a MIME type.
Note that, along with official MIME types, this method also recognizes some unofficial MIME types that are commonly used in practice.
ⓘ
let header = HeaderValue::from_static("application/json");
let content_type = ContentType::from_header(&header).unwrap();
assert_eq!(content_type, ContentType::Json);
let header = HeaderValue::from_static("application/vnd.msgpack");
let content_type = ContentType::from_header(&header).unwrap();
assert_eq!(content_type, ContentType::MsgPack);
let header = HeaderValue::from_static("application/x-msgpack");
let content_type = ContentType::from_header(&header).unwrap();
assert_eq!(content_type, ContentType::MsgPack);
Sourcepub fn as_str(&self) -> &'static str
pub fn as_str(&self) -> &'static str
Returns the MIME type as a string slice.
ⓘ
let content_type = ContentType::Json;
assert_eq!(content_type.as_str(), "application/json");
Sourcepub fn into_header(self) -> HeaderValue
pub fn into_header(self) -> HeaderValue
Converts the ContentType
into a HeaderValue
.
ⓘ
let content_type = ContentType::Json;
let header = content_type.into_header();
assert_eq!(header, HeaderValue::from_static("application/json"));
let content_type = ContentType::MsgPack;
let header = content_type.into_header();
assert_eq!(header, HeaderValue::from_static("application/vnd.msgpack"));
let content_type = ContentType::Yaml;
let header = content_type.into_header();
assert_eq!(header, HeaderValue::from_static("application/x-yaml"));
let content_type = ContentType::Toml;
let header = content_type.into_header();
assert_eq!(header, HeaderValue::from_static("text/toml"));
Trait Implementations§
Source§impl Clone for ContentType
impl Clone for ContentType
Source§fn clone(&self) -> ContentType
fn clone(&self) -> ContentType
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ContentType
impl Debug for ContentType
Source§impl Default for ContentType
impl Default for ContentType
Source§impl Display for ContentType
impl Display for ContentType
Source§impl From<Accept> for ContentType
impl From<Accept> for ContentType
Source§impl<S> FromRequestParts<S> for ContentTypewhere
S: Sync,
impl<S> FromRequestParts<S> for ContentTypewhere
S: Sync,
Source§impl FromStr for ContentType
impl FromStr for ContentType
Source§impl PartialEq for ContentType
impl PartialEq for ContentType
impl Copy for ContentType
impl Eq for ContentType
impl StructuralPartialEq for ContentType
Auto Trait Implementations§
impl Freeze for ContentType
impl RefUnwindSafe for ContentType
impl Send for ContentType
impl Sync for ContentType
impl Unpin for ContentType
impl UnwindSafe for ContentType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.Source§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
Source§type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
Source§async fn from_request(
req: Request<Body>,
state: &S,
) -> Result<T, <T as FromRequest<S, ViaParts>>::Rejection>
async fn from_request( req: Request<Body>, state: &S, ) -> Result<T, <T as FromRequest<S, ViaParts>>::Rejection>
Perform the extraction.
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> ValidateIp for Twhere
T: ToString,
impl<T> ValidateIp for Twhere
T: ToString,
Source§fn validate_ipv4(&self) -> bool
fn validate_ipv4(&self) -> bool
Validates whether the given string is an IP V4
Source§fn validate_ipv6(&self) -> bool
fn validate_ipv6(&self) -> bool
Validates whether the given string is an IP V6
Source§fn validate_ip(&self) -> bool
fn validate_ip(&self) -> bool
Validates whether the given string is an IP