pub trait IntoRes<Encoding, Response, CustErr> {
    // Required method
    fn into_res(
        self,
    ) -> impl Future<Output = Result<Response, ServerFnError<CustErr>>> + Send;
}
Expand description

Serializes the data type into an HTTP response.

Implementations use the methods of the Res trait to create a response. They are often quite short, usually consisting of just two steps:

  1. Serializing the data type to a String, Bytes, or a Stream.
  2. Creating a response with that serialized value as its body.

For example, here’s the implementation for Json.

impl<CustErr, T, Response> IntoRes<Json, Response, CustErr> for T
where
    Response: Res<CustErr>,
    T: Serialize + Send,
{
    async fn into_res(self) -> Result<Response, ServerFnError<CustErr>> {
        // try to serialize the data
        let data = serde_json::to_string(&self)
            .map_err(|e| ServerFnError::Serialization(e.to_string()))?;
        // and use it as the body of a response
        Response::try_from_string(Json::CONTENT_TYPE, data)
    }
}

Required Methods§

Source

fn into_res( self, ) -> impl Future<Output = Result<Response, ServerFnError<CustErr>>> + Send

Attempts to serialize the output into an HTTP response.

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.

Implementors§

Source§

impl<CustErr, Response> IntoRes<Streaming, Response, CustErr> for ByteStream<CustErr>
where Response: Res<CustErr>, CustErr: 'static,

Source§

impl<CustErr, Response> IntoRes<StreamingText, Response, CustErr> for TextStream<CustErr>
where Response: Res<CustErr>, CustErr: 'static,

Source§

impl<CustErr, T, Response> IntoRes<Json, Response, CustErr> for T
where Response: Res<CustErr>, T: Serialize + Send,

Source§

impl<CustErr, T, Response> IntoRes<StreamingJson, Response, CustErr> for JsonStream<T, CustErr>
where Response: Res<CustErr>, CustErr: 'static, T: Serialize + 'static,