pub struct Form<T>(pub T);Expand description
Deserializes an application/x-www-form-urlencoded request body into T.
The body counterpart to Query<T>, and the classic HTML form POST. Like
Json<T> it consumes the body, so it must be
the last handler argument.
Fails with 415 Unsupported Media Type when the content type is not
application/x-www-form-urlencoded, and 400 Bad Request when the body
does not deserialize into T.
Note + means a space here — this is form encoding. In a path segment +
is a literal plus, which is why path decoding uses its own decoder.
use churust_core::{Churust, Form, TestClient};
use serde::Deserialize;
#[derive(Deserialize)]
struct Login { user: String }
let app = Churust::server()
.routing(|r| {
r.post("/login", |Form(l): Form<Login>| async move { l.user });
})
.build();
let res = TestClient::new(app)
.post("/login")
.header("content-type", "application/x-www-form-urlencoded")
.body("user=ana")
.send()
.await;
assert_eq!(res.text(), "ana");Tuple Fields§
§0: TThe deserialized form body.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Form<T>where
T: Freeze,
impl<T> RefUnwindSafe for Form<T>where
T: RefUnwindSafe,
impl<T> Send for Form<T>where
T: Send,
impl<T> Sync for Form<T>where
T: Sync,
impl<T> Unpin for Form<T>where
T: Unpin,
impl<T> UnsafeUnpin for Form<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Form<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