pub struct ContentType(/* private fields */);Expand description
Content-Type header, defined in
RFC7231
The Content-Type header field indicates the media type of the
associated representation: either the representation enclosed in the
message payload or the selected representation, as determined by the
message semantics. The indicated media type defines both the data
format and how that data is intended to be processed by a recipient,
within the scope of the received message semantics, after any content
codings indicated by Content-Encoding are decoded.
Although the mime crate allows the mime options to be any slice, this crate
forces the use of Vec. This is to make sure the same header can’t have more than 1 type. If
this is an issue, it’s possible to implement Header on a custom struct.
§ABNF
Content-Type = media-type§Example values
text/html; charset=utf-8application/json
§Examples
use rama_http_headers::ContentType;
let ct = ContentType::json();Implementations§
Source§impl ContentType
impl ContentType
Sourcepub fn new(mime: Mime) -> Self
pub fn new(mime: Mime) -> Self
Create a new ContentType from any Mime.
pub fn ndjson() -> Self
Sourcepub fn text_utf8() -> Self
pub fn text_utf8() -> Self
A constructor to easily create a Content-Type: text/plain; charset=utf-8 header.
Sourcepub fn text_event_stream() -> Self
pub fn text_event_stream() -> Self
A constructor to easily create a Content-Type: text/event-stream header.
Sourcepub fn html_utf8() -> Self
pub fn html_utf8() -> Self
A constructor to easily create a Content-Type: text/html; charset=utf-8 header.
Sourcepub fn csv_utf8() -> Self
pub fn csv_utf8() -> Self
A constructor to easily create a Content-Type: text/csv; charset=utf-8 header.
Sourcepub fn form_url_encoded() -> Self
pub fn form_url_encoded() -> Self
A constructor to easily create a Content-Type: application/x-www-form-url-encoded header.
Sourcepub fn octet_stream() -> Self
pub fn octet_stream() -> Self
A constructor to easily create a Content-Type: application/octet-stream header.
Sourcepub fn javascript() -> Self
pub fn javascript() -> Self
A constructor to easily create a Content-Type: application/javascript header.
Sourcepub fn javascript_utf8() -> Self
pub fn javascript_utf8() -> Self
A constructor to easily create a Content-Type: application/javascript; charset=utf-8 header.
Sourcepub fn rss() -> Self
pub fn rss() -> Self
A constructor to easily create a Content-Type: application/rss+xml header.
Sourcepub fn atom() -> Self
pub fn atom() -> Self
A constructor to easily create a Content-Type: application/atom+xml header.
Sourcepub fn jose_json() -> Self
pub fn jose_json() -> Self
A constructor to easily create a Content-Type: application/jose+json header.
Sourcepub fn manifest_json() -> Self
pub fn manifest_json() -> Self
A constructor to easily create a Content-Type: application/manifest+json header,
as defined by the W3C Web App Manifest spec.
Sourcepub fn svg() -> Self
pub fn svg() -> Self
A constructor to easily create a Content-Type: image/svg+xml header.
use rama_http_headers::ContentType;
assert_eq!(ContentType::svg().to_string(), "image/svg+xml");Sourcepub fn xml_utf8() -> Self
pub fn xml_utf8() -> Self
A constructor to easily create a Content-Type: application/xml; charset=utf-8 header.
Distinct from Self::xml (which is text/xml): per
RFC 7303 application/xml
is preferred for sitemaps/RSS/Atom, and the charset is stated explicitly
so the document’s XML prolog and the HTTP Content-Type agree.
use rama_http_headers::ContentType;
assert_eq!(
ContentType::xml_utf8().to_string(),
"application/xml; charset=utf-8",
);Sourcepub fn wasm() -> Self
pub fn wasm() -> Self
A constructor to easily create a Content-Type: application/wasm header.
The spec mandates this exact value for WebAssembly.instantiateStreaming
to accept the response.
use rama_http_headers::ContentType;
assert_eq!(ContentType::wasm().to_string(), "application/wasm");Sourcepub fn woff2() -> Self
pub fn woff2() -> Self
A constructor to easily create a Content-Type: font/woff2 header.
use rama_http_headers::ContentType;
assert_eq!(ContentType::woff2().to_string(), "font/woff2");Sourcepub fn webmanifest() -> Self
pub fn webmanifest() -> Self
A constructor to easily create a Content-Type: application/manifest+json header.
Alias of Self::manifest_json, named after the .webmanifest file
extension that web app manifests actually use; both coexist.
use rama_http_headers::ContentType;
assert_eq!(
ContentType::webmanifest().to_string(),
"application/manifest+json",
);Trait Implementations§
Source§impl Clone for ContentType
impl Clone for ContentType
Source§fn clone(&self) -> ContentType
fn clone(&self) -> ContentType
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ContentType
impl Debug for ContentType
Source§impl Display for ContentType
impl Display for ContentType
Source§impl From<ContentType> for Mime
impl From<ContentType> for Mime
Source§fn from(ct: ContentType) -> Self
fn from(ct: ContentType) -> Self
Source§impl From<Mime> for ContentType
impl From<Mime> for ContentType
Source§impl FromStr for ContentType
impl FromStr for ContentType
Source§impl HeaderDecode for ContentType
impl HeaderDecode for ContentType
Source§fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(
values: &mut I,
) -> Result<Self, Error>
fn decode<'i, I: Iterator<Item = &'i HeaderValue>>( values: &mut I, ) -> Result<Self, Error>
HeaderValues.Source§impl HeaderEncode for ContentType
impl HeaderEncode for ContentType
Source§fn encode<E: Extend<HeaderValue>>(&self, values: &mut E)
fn encode<E: Extend<HeaderValue>>(&self, values: &mut E)
HeaderValue, and add it to a container
which has HeaderValue type as each element. Read moreSource§fn encode_to_value(&self) -> Option<HeaderValue>
fn encode_to_value(&self) -> Option<HeaderValue>
HeaderValue. Read moreSource§impl PartialEq for ContentType
impl PartialEq for ContentType
Source§fn eq(&self, other: &ContentType) -> bool
fn eq(&self, other: &ContentType) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for ContentType
Source§impl TypedHeader for ContentType
impl TypedHeader for ContentType
Source§fn name() -> &'static HeaderName
fn name() -> &'static HeaderName
Auto Trait Implementations§
impl Freeze for ContentType
impl RefUnwindSafe for ContentType
impl Send for ContentType
impl Sync for ContentType
impl Unpin for ContentType
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more