pub struct FormRequest<T>(pub T);Expand description
Axum extractor that deserializes a URL-encoded form body into T and then sanitizes it.
Returns a 400 Bad Request error if the body is not valid URL-encoded data or cannot be
deserialized. T must implement both serde::de::DeserializeOwned and
crate::sanitize::Sanitize.
§Example
use modo::extractor::FormRequest;
use modo::Sanitize;
use serde::Deserialize;
#[derive(Deserialize)]
struct LoginForm { username: String, password: String }
impl Sanitize for LoginForm {
fn sanitize(&mut self) { self.username = self.username.trim().to_lowercase(); }
}
async fn login(FormRequest(form): FormRequest<LoginForm>) {
// form.username is already trimmed and lowercased
}Tuple Fields§
§0: TTrait Implementations§
Source§impl<S, T> FromRequest<S> for FormRequest<T>
impl<S, T> FromRequest<S> for FormRequest<T>
Auto Trait Implementations§
impl<T> Freeze for FormRequest<T>where
T: Freeze,
impl<T> RefUnwindSafe for FormRequest<T>where
T: RefUnwindSafe,
impl<T> Send for FormRequest<T>where
T: Send,
impl<T> Sync for FormRequest<T>where
T: Sync,
impl<T> Unpin for FormRequest<T>where
T: Unpin,
impl<T> UnsafeUnpin for FormRequest<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for FormRequest<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