pub struct HtmlForm<T: DeserializeOwned + Send + 'static>(pub T);Expand description
Decodes an x-www-form-urlencoded request body (eg. sent by an HTML form).
This uses serde_urlencoded to deserialize the request body.
The Content-Type and Content-Length headers are ignored.
§Examples
Here’s an example decoding the following HTML form:
<form method="POST" action="/login">
<input name="id" value="12345" type="hidden" />
<input name="user" />
<input name="password" type="password" />
<input type="submit" value="Log In" />
</form>#[derive(Deserialize)]
struct LoginData {
id: u32,
user: String,
password: String,
}
#[derive(FromRequest)]
enum Route {
#[post("/login")]
LogIn {
#[body]
data: HtmlForm<LoginData>,
},
}
let data = "id=12345&user=myuser&password=hunter2";
let Route::LogIn { data: HtmlForm(form) } = Route::from_request_sync(
http::Request::post("/login").body(data.into()).unwrap(),
NoContext,
).unwrap();
assert_eq!(form.id, 12345);
assert_eq!(form.user, "myuser");
assert_eq!(form.password, "hunter2");Tuple Fields§
§0: TTrait Implementations§
Source§impl<T: DeserializeOwned + Send + 'static> FromBody for HtmlForm<T>
impl<T: DeserializeOwned + Send + 'static> FromBody for HtmlForm<T>
impl<T: Eq + DeserializeOwned + Send + 'static> Eq for HtmlForm<T>
impl<T: DeserializeOwned + Send + 'static> StructuralPartialEq for HtmlForm<T>
Auto Trait Implementations§
impl<T> Freeze for HtmlForm<T>where
T: Freeze,
impl<T> RefUnwindSafe for HtmlForm<T>where
T: RefUnwindSafe,
impl<T> Send for HtmlForm<T>
impl<T> Sync for HtmlForm<T>where
T: Sync,
impl<T> Unpin for HtmlForm<T>where
T: Unpin,
impl<T> UnwindSafe for HtmlForm<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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.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