Trait axum::response::IntoResponseParts
source · [−]pub trait IntoResponseParts {
type Error: IntoResponse;
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, Self::Error>;
}
Expand description
Trait for adding headers and extensions to a response.
Example
use axum::{
response::{ResponseParts, IntoResponse, IntoResponseParts, Response},
http::{StatusCode, header::{HeaderName, HeaderValue}},
};
// Hypothetical helper type for setting a single header
struct SetHeader<'a>(&'a str, &'a str);
impl<'a> IntoResponseParts for SetHeader<'a> {
type Error = (StatusCode, String);
fn into_response_parts(self, mut res: ResponseParts) -> Result<ResponseParts, Self::Error> {
match (self.0.parse::<HeaderName>(), self.1.parse::<HeaderValue>()) {
(Ok(name), Ok(value)) => {
res.headers_mut().insert(name, value);
},
(Err(_), _) => {
return Err((
StatusCode::INTERNAL_SERVER_ERROR,
format!("Invalid header name {}", self.0),
));
},
(_, Err(_)) => {
return Err((
StatusCode::INTERNAL_SERVER_ERROR,
format!("Invalid header value {}", self.1),
));
},
}
Ok(res)
}
}
// Its also recommended to implement `IntoResponse` so `SetHeader` can be used on its own as
// the response
impl<'a> IntoResponse for SetHeader<'a> {
fn into_response(self) -> Response {
// This gives an empty response with the header
(self, ()).into_response()
}
}
// We can now return `SetHeader` in responses
//
// Note that returning `impl IntoResponse` might be easier if the response has many parts to
// it. The return type is written out here for clarity.
async fn handler() -> (SetHeader<'static>, SetHeader<'static>, &'static str) {
(
SetHeader("server", "axum"),
SetHeader("x-foo", "custom"),
"body",
)
}
// Or on its own as the whole response
async fn other_handler() -> SetHeader<'static> {
SetHeader("x-foo", "custom")
}
Required Associated Types
sourcetype Error: IntoResponse
type Error: IntoResponse
The type returned in the event of an error.
This can be used to fallibly convert types into headers or extensions.
Required Methods
sourcefn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, Self::Error>
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, Self::Error>
Set parts of the response
Implementations on Foreign Types
sourceimpl<T1, T2, T3, T4> IntoResponseParts for (T1, T2, T3, T4)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
impl<T1, T2, T3, T4> IntoResponseParts for (T1, T2, T3, T4)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
type Error = Response<UnsyncBoxBody<Bytes, Error>>
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <(T1, T2, T3, T4) as IntoResponseParts>::Error>
sourceimpl<T> IntoResponseParts for Option<T>where
T: IntoResponseParts,
impl<T> IntoResponseParts for Option<T>where
T: IntoResponseParts,
type Error = <T as IntoResponseParts>::Error
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <Option<T> as IntoResponseParts>::Error>
sourceimpl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
T8: IntoResponseParts,
T9: IntoResponseParts,
T10: IntoResponseParts,
impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
T8: IntoResponseParts,
T9: IntoResponseParts,
T10: IntoResponseParts,
type Error = Response<UnsyncBoxBody<Bytes, Error>>
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) as IntoResponseParts>::Error>
sourceimpl<T1, T2> IntoResponseParts for (T1, T2)where
T1: IntoResponseParts,
T2: IntoResponseParts,
impl<T1, T2> IntoResponseParts for (T1, T2)where
T1: IntoResponseParts,
T2: IntoResponseParts,
type Error = Response<UnsyncBoxBody<Bytes, Error>>
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <(T1, T2) as IntoResponseParts>::Error>
sourceimpl<T1> IntoResponseParts for (T1,)where
T1: IntoResponseParts,
impl<T1> IntoResponseParts for (T1,)where
T1: IntoResponseParts,
type Error = Response<UnsyncBoxBody<Bytes, Error>>
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <(T1,) as IntoResponseParts>::Error>
sourceimpl<T1, T2, T3, T4, T5, T6> IntoResponseParts for (T1, T2, T3, T4, T5, T6)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
impl<T1, T2, T3, T4, T5, T6> IntoResponseParts for (T1, T2, T3, T4, T5, T6)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
type Error = Response<UnsyncBoxBody<Bytes, Error>>
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <(T1, T2, T3, T4, T5, T6) as IntoResponseParts>::Error>
sourceimpl<T1, T2, T3> IntoResponseParts for (T1, T2, T3)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
impl<T1, T2, T3> IntoResponseParts for (T1, T2, T3)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
type Error = Response<UnsyncBoxBody<Bytes, Error>>
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <(T1, T2, T3) as IntoResponseParts>::Error>
sourceimpl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
T8: IntoResponseParts,
T9: IntoResponseParts,
T10: IntoResponseParts,
T11: IntoResponseParts,
T12: IntoResponseParts,
impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
T8: IntoResponseParts,
T9: IntoResponseParts,
T10: IntoResponseParts,
T11: IntoResponseParts,
T12: IntoResponseParts,
type Error = Response<UnsyncBoxBody<Bytes, Error>>
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) as IntoResponseParts>::Error>
sourceimpl<T1, T2, T3, T4, T5, T6, T7> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
impl<T1, T2, T3, T4, T5, T6, T7> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
type Error = Response<UnsyncBoxBody<Bytes, Error>>
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <(T1, T2, T3, T4, T5, T6, T7) as IntoResponseParts>::Error>
sourceimpl<T1, T2, T3, T4, T5> IntoResponseParts for (T1, T2, T3, T4, T5)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
impl<T1, T2, T3, T4, T5> IntoResponseParts for (T1, T2, T3, T4, T5)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
type Error = Response<UnsyncBoxBody<Bytes, Error>>
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <(T1, T2, T3, T4, T5) as IntoResponseParts>::Error>
sourceimpl<K, V, const N: usize> IntoResponseParts for [(K, V); N]where
K: TryInto<HeaderName>,
V: TryInto<HeaderValue>,
<K as TryInto<HeaderName>>::Error: Display,
<V as TryInto<HeaderValue>>::Error: Display,
impl<K, V, const N: usize> IntoResponseParts for [(K, V); N]where
K: TryInto<HeaderName>,
V: TryInto<HeaderValue>,
<K as TryInto<HeaderName>>::Error: Display,
<V as TryInto<HeaderValue>>::Error: Display,
type Error = TryIntoHeaderError<<K as TryInto<HeaderName>>::Error, <V as TryInto<HeaderValue>>::Error>
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <[(K, V); N] as IntoResponseParts>::Error>
sourceimpl IntoResponseParts for HeaderMap<HeaderValue>
impl IntoResponseParts for HeaderMap<HeaderValue>
type Error = Infallible
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <HeaderMap<HeaderValue> as IntoResponseParts>::Error>
sourceimpl IntoResponseParts for Extensions
impl IntoResponseParts for Extensions
type Error = Infallible
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <Extensions as IntoResponseParts>::Error>
sourceimpl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
T8: IntoResponseParts,
T9: IntoResponseParts,
T10: IntoResponseParts,
T11: IntoResponseParts,
T12: IntoResponseParts,
T13: IntoResponseParts,
T14: IntoResponseParts,
impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
T8: IntoResponseParts,
T9: IntoResponseParts,
T10: IntoResponseParts,
T11: IntoResponseParts,
T12: IntoResponseParts,
T13: IntoResponseParts,
T14: IntoResponseParts,
type Error = Response<UnsyncBoxBody<Bytes, Error>>
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) as IntoResponseParts>::Error>
sourceimpl<T1, T2, T3, T4, T5, T6, T7, T8> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7, T8)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
T8: IntoResponseParts,
impl<T1, T2, T3, T4, T5, T6, T7, T8> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7, T8)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
T8: IntoResponseParts,
type Error = Response<UnsyncBoxBody<Bytes, Error>>
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <(T1, T2, T3, T4, T5, T6, T7, T8) as IntoResponseParts>::Error>
sourceimpl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
T8: IntoResponseParts,
T9: IntoResponseParts,
T10: IntoResponseParts,
T11: IntoResponseParts,
T12: IntoResponseParts,
T13: IntoResponseParts,
T14: IntoResponseParts,
T15: IntoResponseParts,
impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
T8: IntoResponseParts,
T9: IntoResponseParts,
T10: IntoResponseParts,
T11: IntoResponseParts,
T12: IntoResponseParts,
T13: IntoResponseParts,
T14: IntoResponseParts,
T15: IntoResponseParts,
type Error = Response<UnsyncBoxBody<Bytes, Error>>
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) as IntoResponseParts>::Error>
sourceimpl<T1, T2, T3, T4, T5, T6, T7, T8, T9> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7, T8, T9)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
T8: IntoResponseParts,
T9: IntoResponseParts,
impl<T1, T2, T3, T4, T5, T6, T7, T8, T9> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7, T8, T9)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
T8: IntoResponseParts,
T9: IntoResponseParts,
type Error = Response<UnsyncBoxBody<Bytes, Error>>
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <(T1, T2, T3, T4, T5, T6, T7, T8, T9) as IntoResponseParts>::Error>
sourceimpl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
T8: IntoResponseParts,
T9: IntoResponseParts,
T10: IntoResponseParts,
T11: IntoResponseParts,
T12: IntoResponseParts,
T13: IntoResponseParts,
impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
T8: IntoResponseParts,
T9: IntoResponseParts,
T10: IntoResponseParts,
T11: IntoResponseParts,
T12: IntoResponseParts,
T13: IntoResponseParts,
type Error = Response<UnsyncBoxBody<Bytes, Error>>
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) as IntoResponseParts>::Error>
sourceimpl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
T8: IntoResponseParts,
T9: IntoResponseParts,
T10: IntoResponseParts,
T11: IntoResponseParts,
impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
T8: IntoResponseParts,
T9: IntoResponseParts,
T10: IntoResponseParts,
T11: IntoResponseParts,
type Error = Response<UnsyncBoxBody<Bytes, Error>>
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) as IntoResponseParts>::Error>
sourceimpl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
T8: IntoResponseParts,
T9: IntoResponseParts,
T10: IntoResponseParts,
T11: IntoResponseParts,
T12: IntoResponseParts,
T13: IntoResponseParts,
T14: IntoResponseParts,
T15: IntoResponseParts,
T16: IntoResponseParts,
impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> IntoResponseParts for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16)where
T1: IntoResponseParts,
T2: IntoResponseParts,
T3: IntoResponseParts,
T4: IntoResponseParts,
T5: IntoResponseParts,
T6: IntoResponseParts,
T7: IntoResponseParts,
T8: IntoResponseParts,
T9: IntoResponseParts,
T10: IntoResponseParts,
T11: IntoResponseParts,
T12: IntoResponseParts,
T13: IntoResponseParts,
T14: IntoResponseParts,
T15: IntoResponseParts,
T16: IntoResponseParts,
type Error = Response<UnsyncBoxBody<Bytes, Error>>
fn into_response_parts(
self,
res: ResponseParts
) -> Result<ResponseParts, <(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) as IntoResponseParts>::Error>
Implementors
sourceimpl<K, V, const N: usize> IntoResponseParts for AppendHeaders<K, V, N>where
K: TryInto<HeaderName>,
V: TryInto<HeaderValue>,
<K as TryInto<HeaderName>>::Error: Display,
<V as TryInto<HeaderValue>>::Error: Display,
impl<K, V, const N: usize> IntoResponseParts for AppendHeaders<K, V, N>where
K: TryInto<HeaderName>,
V: TryInto<HeaderValue>,
<K as TryInto<HeaderName>>::Error: Display,
<V as TryInto<HeaderValue>>::Error: Display,
type Error = TryIntoHeaderError<<K as TryInto<HeaderName>>::Error, <V as TryInto<HeaderValue>>::Error>
sourceimpl<T> IntoResponseParts for Extension<T>where
T: Send + Sync + 'static,
impl<T> IntoResponseParts for Extension<T>where
T: Send + Sync + 'static,
type Error = Infallible
sourceimpl<T> IntoResponseParts for TypedHeader<T>where
T: Header,
Available on crate feature headers
only.
impl<T> IntoResponseParts for TypedHeader<T>where
T: Header,
Available on crate feature
headers
only.