Skip to main content

IntoRes

Trait IntoRes 

pub trait IntoRes<Encoding, Response, E> {
    // Required method
    fn into_res(self) -> impl Future<Output = Result<Response, E>> + 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<E, T, Response> IntoRes<Json, Response, E> for T
where
    Response: Res<E>,
    T: Serialize + Send,
    E: FromServerFnError,
{
    async fn into_res(self) -> Result<Response, E> {
        // try to serialize the data
        let data = serde_json::to_string(&self)
            .map_err(|e| ServerFnErrorErr::Serialization(e.to_string()).into())?;
        // and use it as the body of a response
        Response::try_from_string(Json::CONTENT_TYPE, data)
    }
}

Required Methods§

fn into_res(self) -> impl Future<Output = Result<Response, E>> + 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".

Implementors§

§

impl<E, Response, Encoding, T> IntoRes<Patch<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

§

impl<E, Response, Encoding, T> IntoRes<Post<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

§

impl<E, Response, Encoding, T> IntoRes<Put<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

§

impl<E, Response> IntoRes<Streaming, Response, E> for ByteStream<E>
where Response: TryRes<E>, E: FromServerFnError,

§

impl<E, Response> IntoRes<StreamingText, Response, E> for TextStream<E>
where Response: TryRes<E>, E: FromServerFnError,