1use crate::response::Response;
2
3pub trait IntoResponse: Send {
27 fn into_response(self) -> Response;
29}
30
31impl IntoResponse for String {
33 fn into_response(self) -> Response {
34 Response::text(self)
35 }
36}
37
38impl IntoResponse for &'static str {
39 fn into_response(self) -> Response {
40 Response::text(self)
41 }
42}
43
44impl IntoResponse for std::borrow::Cow<'static, str> {
45 fn into_response(self) -> Response {
46 Response::text(self)
47 }
48}
49
50impl IntoResponse for Response {
52 fn into_response(self) -> Response {
53 self
54 }
55}
56
57impl IntoResponse for () {
59 fn into_response(self) -> Response {
60 Response::empty()
61 }
62}
63
64impl<T: IntoResponse> IntoResponse for Option<T> {
66 fn into_response(self) -> Response {
67 match self {
68 Some(value) => value.into_response(),
69 None => Response::empty(),
70 }
71 }
72}
73
74impl<T: IntoResponse, E: std::fmt::Display + Send> IntoResponse for Result<T, E> {
76 fn into_response(self) -> Response {
77 match self {
78 Ok(value) => value.into_response(),
79 Err(e) => Response::text(format!("Error: {}", e)),
80 }
81 }
82}
83
84impl IntoResponse for async_fs::File {
86 fn into_response(self) -> Response {
87 Response::file(self)
88 }
89}
90
91impl IntoResponse for (async_fs::File, &'static str) {
93 fn into_response(self) -> Response {
94 Response::file(self.0).with_caption(self.1)
95 }
96}
97
98impl IntoResponse for (async_fs::File, String) {
100 fn into_response(self) -> Response {
101 Response::file(self.0).with_caption(self.1)
102 }
103}