1
0
Fork 0
mirror of https://github.com/tokio-rs/axum.git synced 2025-03-30 11:19:20 +02:00

Remove IntoResponse and IntoResponseParts impls for Version ()

This commit is contained in:
David Pedersen 2022-03-02 14:07:16 +01:00 committed by GitHub
parent 84c725a1ae
commit 5f54855b05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 65 deletions
axum-core/src/response
axum/src/docs

View file

@ -3,7 +3,7 @@ use crate::{body, BoxError};
use bytes::{buf::Chain, Buf, Bytes, BytesMut};
use http::{
header::{self, HeaderMap, HeaderName, HeaderValue},
StatusCode, Version,
StatusCode,
};
use http_body::{
combinators::{MapData, MapErr},
@ -136,14 +136,6 @@ impl IntoResponse for StatusCode {
}
}
impl IntoResponse for Version {
fn into_response(self) -> Response {
let mut res = ().into_response();
*res.version_mut() = self;
res
}
}
impl IntoResponse for () {
fn into_response(self) -> Response {
Empty::new().into_response()
@ -384,30 +376,6 @@ where
}
}
impl<R> IntoResponse for (Version, R)
where
R: IntoResponse,
{
fn into_response(self) -> Response {
let mut res = self.1.into_response();
*res.version_mut() = self.0;
res
}
}
impl<R> IntoResponse for (Version, StatusCode, R)
where
R: IntoResponse,
{
fn into_response(self) -> Response {
let (version, status, res) = self;
let mut res = res.into_response();
*res.version_mut() = version;
*res.status_mut() = status;
res
}
}
impl IntoResponse for HeaderMap {
fn into_response(self) -> Response {
let mut res = ().into_response();
@ -501,34 +469,6 @@ macro_rules! impl_into_response {
res
}
}
#[allow(non_snake_case)]
impl<R, $($ty,)*> IntoResponse for (Version, StatusCode, $($ty),*, R)
where
$( $ty: IntoResponseParts, )*
R: IntoResponse,
{
fn into_response(self) -> Response {
let (version, status, $($ty),*, res) = self;
let res = res.into_response();
let parts = ResponseParts { res };
$(
let parts = match $ty.into_response_parts(parts) {
Ok(parts) => parts,
Err(err) => {
return err.into_response();
}
};
)*
let mut res = parts.res;
*res.version_mut() = version;
*res.status_mut() = status;
res
}
}
}
}

View file

@ -149,13 +149,10 @@ async fn all_the_things(uri: Uri) -> impl IntoResponse {
In general you can return tuples like:
- `(StatusCode, impl IntoResponse)`
- `(Version, impl IntoResponse)`
- `(StatusCode, Version, impl IntoResponse)`
- `(T1, .., Tn, impl IntoResponse)` where `T1` to `Tn` all implement [`IntoResponseParts`].
- `(StatusCode, T1, .., Tn, impl IntoResponse)` where `T1` to `Tn` all implement [`IntoResponseParts`].
- `(StatusCode, Version, T1, .., Tn, impl IntoResponse)` where `T1` to `Tn` all implement [`IntoResponseParts`].
This means you cannot accidentally override the status, version, or body, as [`IntoResponseParts`] only allows
This means you cannot accidentally override the status or body as [`IntoResponseParts`] only allows
setting headers and extensions.
Use [`Response`](crate::response::Response) for more low level control: