[−][src]Struct hyperdrive::body::Json
Decodes a JSON-encoded request body.
The FromBody
implementation of this type will retrieve the request body
and decode it as JSON using serde_json
. The Content-Type
and
Content-Length
headers are ignored.
Examples
#[derive(Deserialize)] struct BodyData { id: u32, names: Vec<String>, } #[derive(FromRequest)] enum Route { #[post("/json")] Index { #[body] data: Json<BodyData>, }, } let data = r#" { "id": 123, "names": [ "Joachim", "Johannes", "Jonathan" ] } "#; let Route::Index { data: Json(body) } = Route::from_request_sync( http::Request::post("/json").body(data.into()).unwrap(), NoContext, ).unwrap(); assert_eq!(body.id, 123); assert_eq!(body.names, vec![ "Joachim".to_string(), "Johannes".to_string(), "Jonathan".to_string(), ]);
Trait Implementations
impl<T: DeserializeOwned + Send + 'static> FromBody for Json<T>
[src]
type Context = NoContext
A context parameter passed to [from_body
]. Read more
type Result = DefaultFuture<Self, BoxedError>
The result returned by [from_body
]. Read more
fn from_body(
_request: &Arc<Request<()>>,
body: Body,
_context: &Self::Context
) -> Self::Result
[src]
_request: &Arc<Request<()>>,
body: Body,
_context: &Self::Context
) -> Self::Result
impl<T: PartialEq + DeserializeOwned + Send + 'static> PartialEq<Json<T>> for Json<T>
[src]
impl<T: Eq + DeserializeOwned + Send + 'static> Eq for Json<T>
[src]
impl<T: DeserializeOwned + Send + 'static> DerefMut for Json<T>
[src]
impl<T: DeserializeOwned + Send + 'static> Deref for Json<T>
[src]
impl<T: Debug + DeserializeOwned + Send + 'static> Debug for Json<T>
[src]
Auto Trait Implementations
impl<T> Unpin for Json<T> where
T: Unpin,
T: Unpin,
impl<T> Sync for Json<T> where
T: Sync,
T: Sync,
impl<T> Send for Json<T>
impl<T> UnwindSafe for Json<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T> RefUnwindSafe for Json<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,