pub struct ProblemRejection {
pub problem: Problem,
pub format: ProblemFormat,
}Expand description
The rejection produced by ProblemJson and ProblemValidatedJson: an
RFC 9457 Problem plus the ProblemFormat negotiated from the
request’s Accept headers.
IntoResponse delegates to Problem::into_response_with, so the
response carries the negotiated Content-Type with the problem body. Both
fields are public, making the rejection inspectable in tests and reusable
as the rejection type of custom extractors.
Requires the problem feature plus at least one of extract or
validator.
§Example
use axum::{http::{header, StatusCode}, response::IntoResponse};
use axum_api_kit::{Problem, ProblemFormat, ProblemRejection};
let rejection = ProblemRejection {
problem: Problem::new(StatusCode::UNPROCESSABLE_ENTITY, "Unprocessable Entity")
.with_detail("validation failed"),
format: ProblemFormat::ProblemJson,
};
let res = rejection.into_response();
assert_eq!(res.status(), StatusCode::UNPROCESSABLE_ENTITY);
assert_eq!(
res.headers().get(header::CONTENT_TYPE).unwrap(),
"application/problem+json"
);Fields§
§problem: ProblemThe RFC 9457 problem details body (status, title, detail, and the
code / details extension members carried over from the flat
rejection mapping).
format: ProblemFormatThe response format negotiated from the request’s Accept headers.
Trait Implementations§
Source§impl Clone for ProblemRejection
impl Clone for ProblemRejection
Source§fn clone(&self) -> ProblemRejection
fn clone(&self) -> ProblemRejection
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ProblemRejection
impl Debug for ProblemRejection
Source§impl IntoResponse for ProblemRejection
impl IntoResponse for ProblemRejection
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Create a response.
Auto Trait Implementations§
impl Freeze for ProblemRejection
impl RefUnwindSafe for ProblemRejection
impl Send for ProblemRejection
impl Sync for ProblemRejection
impl Unpin for ProblemRejection
impl UnsafeUnpin for ProblemRejection
impl UnwindSafe for ProblemRejection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, S> Handler<IntoResponseHandler, S> for T
impl<T, S> Handler<IntoResponseHandler, S> for T
Source§fn call(
self,
_req: Request<Body>,
_state: S,
) -> <T as Handler<IntoResponseHandler, S>>::Future
fn call( self, _req: Request<Body>, _state: S, ) -> <T as Handler<IntoResponseHandler, S>>::Future
Call the handler with the given request.
Source§fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
Apply a
tower::Layer to the handler. Read moreSource§fn with_state(self, state: S) -> HandlerService<Self, T, S>
fn with_state(self, state: S) -> HandlerService<Self, T, S>
Convert the handler into a
Service by providing the stateSource§impl<H, T> HandlerWithoutStateExt<T> for H
impl<H, T> HandlerWithoutStateExt<T> for H
Source§fn into_service(self) -> HandlerService<H, T, ()>
fn into_service(self) -> HandlerService<H, T, ()>
Convert the handler into a
Service and no state.Source§fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
Convert the handler into a
MakeService and no state. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more