mirror of
https://github.com/tokio-rs/axum.git
synced 2025-10-02 23:34:47 +00:00
More flexible generic responses
This commit is contained in:
parent
028c472c84
commit
e544fe1c39
@ -137,22 +137,21 @@ impl IntoResponse for StatusCode {
|
|||||||
|
|
||||||
impl<T> IntoResponse for (StatusCode, T)
|
impl<T> IntoResponse for (StatusCode, T)
|
||||||
where
|
where
|
||||||
T: Into<Body>,
|
T: IntoResponse,
|
||||||
{
|
{
|
||||||
fn into_response(self) -> Response<Body> {
|
fn into_response(self) -> Response<Body> {
|
||||||
Response::builder()
|
let mut res = self.1.into_response();
|
||||||
.status(self.0)
|
*res.status_mut() = self.0;
|
||||||
.body(self.1.into())
|
res
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> IntoResponse for (HeaderMap, T)
|
impl<T> IntoResponse for (HeaderMap, T)
|
||||||
where
|
where
|
||||||
T: Into<Body>,
|
T: IntoResponse,
|
||||||
{
|
{
|
||||||
fn into_response(self) -> Response<Body> {
|
fn into_response(self) -> Response<Body> {
|
||||||
let mut res = Response::new(self.1.into());
|
let mut res = self.1.into_response();
|
||||||
*res.headers_mut() = self.0;
|
*res.headers_mut() = self.0;
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
@ -160,10 +159,10 @@ where
|
|||||||
|
|
||||||
impl<T> IntoResponse for (StatusCode, HeaderMap, T)
|
impl<T> IntoResponse for (StatusCode, HeaderMap, T)
|
||||||
where
|
where
|
||||||
T: Into<Body>,
|
T: IntoResponse,
|
||||||
{
|
{
|
||||||
fn into_response(self) -> Response<Body> {
|
fn into_response(self) -> Response<Body> {
|
||||||
let mut res = Response::new(self.2.into());
|
let mut res = self.2.into_response();
|
||||||
*res.status_mut() = self.0;
|
*res.status_mut() = self.0;
|
||||||
*res.headers_mut() = self.1;
|
*res.headers_mut() = self.1;
|
||||||
res
|
res
|
||||||
|
Loading…
x
Reference in New Issue
Block a user