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:
- Serializing the data type to a
String
,Bytes
, or aStream
. - 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§
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.