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) -> ContentType
pub fn new(mime: Mime) -> ContentType
Create a new ContentType from any Mime.
Sourcepub fn json() -> ContentType
pub fn json() -> ContentType
A constructor to easily create a Content-Type: application/json header.
pub fn ndjson() -> ContentType
Sourcepub fn text() -> ContentType
pub fn text() -> ContentType
A constructor to easily create a Content-Type: text/plain header.
Sourcepub fn text_utf8() -> ContentType
pub fn text_utf8() -> ContentType
A constructor to easily create a Content-Type: text/plain; charset=utf-8 header.
Sourcepub fn text_event_stream() -> ContentType
pub fn text_event_stream() -> ContentType
A constructor to easily create a Content-Type: text/event-stream header.
Sourcepub fn html() -> ContentType
pub fn html() -> ContentType
A constructor to easily create a Content-Type: text/html header.
Sourcepub fn html_utf8() -> ContentType
pub fn html_utf8() -> ContentType
A constructor to easily create a Content-Type: text/html; charset=utf-8 header.
Sourcepub fn css() -> ContentType
pub fn css() -> ContentType
A constructor to easily create a Content-Type: text/css header.
Sourcepub fn css_utf8() -> ContentType
pub fn css_utf8() -> ContentType
A constructor to easily create a text/css; charset=utf-8 header.
Sourcepub fn xml() -> ContentType
pub fn xml() -> ContentType
A constructor to easily create a Content-Type: text/xml header.
Sourcepub fn csv() -> ContentType
pub fn csv() -> ContentType
A constructor to easily create a Content-Type: text/csv header.
Sourcepub fn csv_utf8() -> ContentType
pub fn csv_utf8() -> ContentType
A constructor to easily create a Content-Type: text/csv; charset=utf-8 header.
Sourcepub fn form_url_encoded() -> ContentType
pub fn form_url_encoded() -> ContentType
A constructor to easily create a Content-Type: application/x-www-form-url-encoded header.
Sourcepub fn jpeg() -> ContentType
pub fn jpeg() -> ContentType
A constructor to easily create a Content-Type: image/jpeg header.
Sourcepub fn png() -> ContentType
pub fn png() -> ContentType
A constructor to easily create a Content-Type: image/png header.
Sourcepub fn octet_stream() -> ContentType
pub fn octet_stream() -> ContentType
A constructor to easily create a Content-Type: application/octet-stream header.
Sourcepub fn javascript() -> ContentType
pub fn javascript() -> ContentType
A constructor to easily create a Content-Type: application/javascript header.
Sourcepub fn grpc() -> ContentType
pub fn grpc() -> ContentType
A constructor to easily create a Content-Type: application/grpc header.
Sourcepub fn javascript_utf8() -> ContentType
pub fn javascript_utf8() -> ContentType
A constructor to easily create a Content-Type: application/javascript; charset=utf-8 header.
Sourcepub fn rss() -> ContentType
pub fn rss() -> ContentType
A constructor to easily create a Content-Type: application/rss+xml header.
Sourcepub fn atom() -> ContentType
pub fn atom() -> ContentType
A constructor to easily create a Content-Type: application/atom+xml header.
Sourcepub fn jose_json() -> ContentType
pub fn jose_json() -> ContentType
A constructor to easily create a Content-Type: application/jose+json header.
Sourcepub fn manifest_json() -> ContentType
pub fn manifest_json() -> ContentType
A constructor to easily create a Content-Type: application/manifest+json header,
as defined by the W3C Web App Manifest spec.
Sourcepub fn svg() -> ContentType
pub fn svg() -> ContentType
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() -> ContentType
pub fn xml_utf8() -> ContentType
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() -> ContentType
pub fn wasm() -> ContentType
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() -> ContentType
pub fn woff2() -> ContentType
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() -> ContentType
pub fn webmanifest() -> ContentType
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) -> Mime
fn from(ct: ContentType) -> Mime
Source§impl From<Mime> for ContentType
impl From<Mime> for ContentType
Source§fn from(m: Mime) -> ContentType
fn from(m: Mime) -> ContentType
Source§impl FromStr for ContentType
impl FromStr for ContentType
Source§impl HeaderDecode for ContentType
impl HeaderDecode for ContentType
Source§fn decode<'i, I>(values: &mut I) -> Result<ContentType, Error>where
I: Iterator<Item = &'i HeaderValue>,
fn decode<'i, I>(values: &mut I) -> Result<ContentType, Error>where
I: Iterator<Item = &'i HeaderValue>,
HeaderValues.Source§impl HeaderEncode for ContentType
impl HeaderEncode for ContentType
Source§fn encode<E>(&self, values: &mut E)where
E: Extend<HeaderValue>,
fn encode<E>(&self, values: &mut E)where
E: Extend<HeaderValue>,
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<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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 moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
Source§impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
type Error = <U as RamaTryFrom<T, CrateMarker>>::Error
fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T, CrateMarker>>::Error>
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.