Trait Response

Source
pub trait Response {
    type Buf: Buf;
    type Body: BufStream<Item = Self::Buf, Error = Error>;

    // Required method
    fn into_http<S: Serializer>(
        self,
        context: &Context<'_, S>,
    ) -> Result<Response<Self::Body>, Error>;
}
Expand description

Types that can be returned from resources as responses to HTTP requests.

Implementations of Response are responsible for encoding the value using the appropriate content type. The content type may be specific to the type in question, for example serde_json::Value implies a content type of application/json.

Alternatively, the provided context may be used to encode the response in most suitable content-type based on the request context. The content-type is picked using the following factors:

  • The HTTP request’s Accept header value (not yet implemented).
  • Any content type specified by the resource using annotations.
  • Serialization formats that the application made available to the resource.

Implementations of Response are able to asynchronously stream the response body if needed. This is done by setting the HTTP response body to a BufStream type that supports streaming.

Required Associated Types§

Source

type Buf: Buf

Data chunk type.

Source

type Body: BufStream<Item = Self::Buf, Error = Error>

The HTTP response body type.

Required Methods§

Source

fn into_http<S: Serializer>( self, context: &Context<'_, S>, ) -> Result<Response<Self::Body>, Error>

Convert the value into a response future

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Response for &'static str

Source§

type Buf = Cursor<&'static [u8]>

Source§

type Body = Map<&'static str>

Source§

fn into_http<S: Serializer>( self, context: &Context<'_, S>, ) -> Result<Response<Self::Body>, Error>

Source§

impl Response for Value

Source§

type Buf = <<Value as Response>::Body as BufStream>::Item

Source§

type Body = Map<Bytes>

Source§

fn into_http<S>( self, context: &Context<'_, S>, ) -> Result<Response<Self::Body>, Error>
where S: Serializer,

Source§

impl Response for String

Source§

type Buf = Cursor<Vec<u8>>

Source§

type Body = Map<String>

Source§

fn into_http<S: Serializer>( self, context: &Context<'_, S>, ) -> Result<Response<Self::Body>, Error>

Source§

impl Response for File

Source§

type Buf = Cursor<BytesMut>

Source§

type Body = Map<File>

Source§

fn into_http<S: Serializer>( self, context: &Context<'_, S>, ) -> Result<Response<Self::Body>, Error>

Source§

impl<A, B> Response for Either<A, B>
where A: Response, B: Response,

Source§

type Buf = <<Either<A, B> as Response>::Body as BufStream>::Item

Source§

type Body = Either2<<A as Response>::Body, <B as Response>::Body>

Source§

fn into_http<S: Serializer>( self, context: &Context<'_, S>, ) -> Result<Response<Self::Body>, Error>

Source§

impl<R, E> Response for Result<R, E>
where R: Response, E: Into<Error>,

Source§

type Buf = <R as Response>::Buf

Source§

type Body = <R as Response>::Body

Source§

fn into_http<S: Serializer>( self, context: &Context<'_, S>, ) -> Result<Response<Self::Body>, Error>

Source§

impl<T> Response for Vec<T>
where T: Serialize,

Source§

type Buf = <SerdeResponse<Vec<T>> as Response>::Buf

Source§

type Body = <SerdeResponse<Vec<T>> as Response>::Body

Source§

fn into_http<S>( self, context: &Context<'_, S>, ) -> Result<Response<Self::Body>, Error>
where S: Serializer,

Source§

impl<T> Response for Response<T>
where T: BufStream,

Source§

type Buf = <T as BufStream>::Item

Source§

type Body = Map<T>

Source§

fn into_http<S: Serializer>( self, _: &Context<'_, S>, ) -> Result<Response<Self::Body>, Error>

Source§

impl<T: Response> Response for Option<T>

Source§

type Buf = <T as Response>::Buf

Source§

type Body = <T as Response>::Body

Source§

fn into_http<S: Serializer>( self, context: &Context<'_, S>, ) -> Result<Response<Self::Body>, Error>

Implementors§