via/response/
into_response.rs1use super::{Response, ResponseBuilder};
2use crate::{Error, Result};
3
4pub trait IntoResponse {
5 fn into_response(self) -> Result<Response>;
6}
7
8impl IntoResponse for () {
9 fn into_response(self) -> Result<Response> {
10 Ok(Default::default())
11 }
12}
13
14impl IntoResponse for Vec<u8> {
15 fn into_response(self) -> Result<Response> {
16 Response::build().body(self).finish()
17 }
18}
19
20impl IntoResponse for &'static [u8] {
21 fn into_response(self) -> Result<Response> {
22 Response::build().body(self).finish()
23 }
24}
25
26impl IntoResponse for String {
27 fn into_response(self) -> Result<Response> {
28 Ok(Response::text(self))
29 }
30}
31
32impl IntoResponse for &'static str {
33 fn into_response(self) -> Result<Response> {
34 self.to_string().into_response()
35 }
36}
37
38impl IntoResponse for Response {
39 fn into_response(self) -> Result<Response> {
40 Ok(self)
41 }
42}
43
44impl IntoResponse for ResponseBuilder {
45 fn into_response(self) -> Result<Response> {
46 self.finish()
47 }
48}
49
50impl<T, E> IntoResponse for Result<T, E>
51where
52 T: IntoResponse,
53 Error: From<E>,
54{
55 fn into_response(self) -> Result<Response> {
56 self?.into_response()
57 }
58}