Skip to main content

ContentType

Enum ContentType 

Source
pub enum ContentType {
Show 14 variants Json, Yaml, Cbor, MsgPack, Csv, Proto, FormUrlEncoded, MultipartForm, Sse, WebSocket, GrpcWeb, OpenApi, Mcp, Markdown,
}
Expand description

Supported content types, transports, and discovery formats.

Copy, stack-allocated, zero-cost to pass around.

Variants§

§

Json

JSON (application/json) — default

§

Yaml

YAML (application/yaml)

§

Cbor

CBOR (application/cbor) — binary

§

MsgPack

MessagePack (application/msgpack) — binary

§

Csv

CSV (text/csv) — tabular

§

Proto

Protobuf (application/proto) — binary, also Connect/gRPC

§

FormUrlEncoded

Form URL-encoded (application/x-www-form-urlencoded) — request deserialization

§

MultipartForm

Multipart form data (multipart/form-data) — request deserialization

§

Sse

Server-Sent Events (text/event-stream)

§

WebSocket

WebSocket (Upgrade: websocket)

§

GrpcWeb

gRPC-Web / Connect server-streaming (application/grpc-web+json). Length-prefixed envelope frames [flag:u8][len:u32 BE][payload] over a held-open HTTP/2 response — the browser-reachable member of the gRPC family (raw gRPC needs HTTP/2 trailers the fetch API can’t read). Shares the subscribe path with Self::Sse; only the frame encoding differs.

§

OpenApi

OpenAPI 3.1 spec

§

Mcp

MCP tools/list response

§

Markdown

Human-readable Markdown

Implementations§

Source§

impl ContentType

Source

pub fn from_extension(ext: &str) -> Option<Self>

Parse from URL file extension.

Source

pub fn from_content_type_header(header: &str) -> Option<Self>

Parse from Content-Type request header for transport/format detection.

Returns None for standard types that don’t need special routing.

Source

pub fn from_accept_header(accept: Option<&str>) -> Self

Parse from Accept header value. Falls back to Json.

Source

pub fn from_query_param(query: &str) -> Option<Self>

Parse from ?format= query parameter.

Source

pub const fn header_value(self) -> &'static str

Content-Type header value for the response.

Source

pub const fn is_streaming(self) -> bool

Whether this is a streaming transport (SSE, WebSocket, gRPC-Web).

Source

pub const fn is_streaming_subscribe(self) -> bool

Whether this is a server-to-client streaming-subscribe transport (SSE or gRPC-Web) — the formats the subscribe handler serves over a held-open response. Excludes WebSocket (handled by an upgrade in the host layer before dispatch).

Source

pub const fn is_data_format(self) -> bool

Whether this is a data serialization format.

Trait Implementations§

Source§

impl Clone for ContentType

Source§

fn clone(&self) -> ContentType

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ContentType

Source§

impl Debug for ContentType

Source§

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

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

impl Default for ContentType

Source§

fn default() -> ContentType

Returns the “default value” for a type. Read more
Source§

impl Eq for ContentType

Source§

impl Hash for ContentType

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 for ContentType

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for ContentType

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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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, 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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more