Struct HtmlForm

Source
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: T

Trait Implementations§

Source§

impl<T: Debug + DeserializeOwned + Send + 'static> Debug for HtmlForm<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: DeserializeOwned + Send + 'static> DerefMut for HtmlForm<T>

Source§

fn deref_mut(&mut self) -> &mut T

Mutably dereferences the value.
Source§

impl<T: DeserializeOwned + Send + 'static> FromBody for HtmlForm<T>

Source§

type Context = NoContext

A context parameter passed to from_body. Read more
Source§

type Result = Box<dyn Future<Item = HtmlForm<T>, Error = Box<dyn Error + Send + Sync>> + Send>

The result returned by from_body. Read more
Source§

fn from_body( _request: &Arc<Request<()>>, body: Body, _context: &Self::Context, ) -> Self::Result

Create an instance of this type from an HTTP request body, asynchronously. Read more
Source§

impl<T: PartialEq + DeserializeOwned + Send + 'static> PartialEq for HtmlForm<T>

Source§

fn eq(&self, other: &HtmlForm<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: DeserializeOwned + Send + 'static> Deref for HtmlForm<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T: Eq + DeserializeOwned + Send + 'static> Eq for HtmlForm<T>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,