pub struct Json<T>(pub T);Expand description
The JSON request body, deserialised.
#[derive(serde::Deserialize)]
struct NewPost { title: String }
let request = Arc::new(
Request::builder().json(&serde_json::json!({ "title": "Hello" })).build(),
);
let Json(post) = Json::<NewPost>::from_request(request).await.unwrap();
assert_eq!(post.title, "Hello");Tuple Fields§
§0: TTrait Implementations§
impl<T: Copy> Copy for Json<T>
Source§impl<T: DeserializeOwned + Send + 'static> FromRequest for Json<T>
impl<T: DeserializeOwned + Send + 'static> FromRequest for Json<T>
Source§fn from_request(request: Arc<Request>) -> BoxedFuture<Result<Self>>
fn from_request(request: Arc<Request>) -> BoxedFuture<Result<Self>>
Build
Self from the request, or fail with the error the client should
see (a 400 for a malformed body, a 422 for a failed contract).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> UnsafeUnpin for Json<T>where
T: UnsafeUnpin,
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