pub struct Json<T>(pub T);Expand description
JSON body extractor
Parses the request body as JSON and deserializes into type T.
Also works as a response type when T: Serialize.
§Example
ⓘ
#[derive(Deserialize)]
struct CreateUser {
name: String,
email: String,
}
async fn create_user(Json(body): Json<CreateUser>) -> impl IntoResponse {
// body is already deserialized
}Tuple Fields§
§0: TTrait Implementations§
Source§impl<T> FromRequest for Json<T>where
T: DeserializeOwned + Send,
impl<T> FromRequest for Json<T>where
T: DeserializeOwned + Send,
Source§impl<T> IntoResponse for Json<T>where
T: Serialize,
impl<T> IntoResponse for Json<T>where
T: Serialize,
Source§fn into_response(self) -> Response<Body>
fn into_response(self) -> Response<Body>
Convert self into a Response
Source§impl<T> OperationModifier for Json<T>where
T: for<'a> ToSchema<'a>,
impl<T> OperationModifier for Json<T>where
T: for<'a> ToSchema<'a>,
Source§fn update_operation(op: &mut Operation)
fn update_operation(op: &mut Operation)
Update the operation
Source§impl<T> ResponseModifier for Json<T>where
T: for<'a> ToSchema<'a>,
impl<T> ResponseModifier for Json<T>where
T: for<'a> ToSchema<'a>,
Source§fn update_response(op: &mut Operation)
fn update_response(op: &mut Operation)
Update the operation with response information
impl<T> Copy for Json<T>where
T: Copy,
Auto Trait Implementations§
impl<T> Freeze for Json<T>where
T: Freeze,
impl<T> RefUnwindSafe for Json<T>where
T: RefUnwindSafe,
impl<T> Send for Json<T>where
T: Send,
impl<T> Sync for Json<T>where
T: Sync,
impl<T> Unpin for Json<T>where
T: Unpin,
impl<T> UnwindSafe for Json<T>where
T: UnwindSafe,
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, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
Source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
The equivalent of
Access::load.Source§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