pub struct Json<T>(pub T)
where
T: for<'de> Deserialize<'de> + Send;
Expand description
Represented as json data
when post
as a application/json
, we can using this struct to inject data,
note: the struct must impl serde::Deserialize
and Send
§Example
#[derive(Deserialize, Debug)]
struct Params {
name: String,
zip: String,
}
pub async fn handle(Json(params) : Json<Params>) -> String {
format!("received params: {:?}", params)
}
Tuple Fields§
§0: T
Trait Implementations§
Source§impl<T> FromRequest for Json<T>where
T: for<'de> Deserialize<'de> + Send,
Extracts JSON data from request body
impl<T> FromRequest for Json<T>where
T: for<'de> Deserialize<'de> + Send,
Extracts JSON data from request body
This implementation expects the request body to be valid JSON
and deserializes it into the target type using serde_json
.
type Output<'r> = Json<T>
type Error = ParseError
async fn from_request<'r>( req: &'r RequestContext<'_, '_>, body: OptionReqBody, ) -> Result<Self::Output<'r>, Self::Error>
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>
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