Trait server_fn::codec::IntoRes

source ·
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.

Object Safety§

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<Cbor, Response, CustErr> for T
where Response: Res<CustErr>, T: Serialize + Send,

source§

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

source§

impl<CustErr, T, Response> IntoRes<Rkyv, Response, CustErr> for T
where Response: Res<CustErr>, T: Serialize<AllocSerializer<1024>> + Send + Archive, T::Archived: for<'a> CheckBytes<DefaultValidator<'a>> + Deserialize<T, SharedDeserializeMap>,

source§

impl<CustErr, T, Response> IntoRes<SerdeLite, 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,

source§

impl<T, Response, Err> IntoRes<MsgPack, Response, Err> for T
where Response: Res<Err>, T: Serialize + Send,