pub struct Form<T>(pub T);
Expand description
Form can be used for extracting typed information and validation from request’s form data.
To extract and typed information from request’s form data, the type T
must
implement the Deserialize
trait from serde
and Validate
trait from validator crate.
FormConfig allows to configure extraction process.
§Example
use actix_web::{web, App};
use actix_web_validator::Form;
use serde::Deserialize;
use validator::Validate;
#[derive(Deserialize, Validate)]
struct Info {
#[validate(length(min = 3))]
username: String,
}
/// deserialize `Info` from request's form data
async fn index(info: Form<Info>) -> String {
format!("Welcome {}!", info.username)
}
fn main() {
let app = App::new().service(
web::resource("/index.html").route(
web::post().to(index))
);
}
Tuple Fields§
§0: T
Implementations§
Source§impl<T> Form<T>
impl<T> Form<T>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Deconstruct to an inner value
Trait Implementations§
Source§impl<T> FromRequest for Form<T>where
T: DeserializeOwned + Validate + 'static,
Form data helper (application/x-www-form-urlencoded
). Allow to extract typed information from request’s
payload and validate it.
impl<T> FromRequest for Form<T>where
T: DeserializeOwned + Validate + 'static,
Form data helper (application/x-www-form-urlencoded
). Allow to extract typed information from request’s
payload and validate it.
To extract typed information from request’s body, the type T
must
implement the Deserialize
trait from serde.
To validate payload, the type T
must implement the Validate
trait
from validator crate.
FormConfig allows to configure extraction process.
§Example
use actix_web::{web, App};
use actix_web_validator::Form;
use serde::Deserialize;
use validator::Validate;
#[derive(Deserialize, Validate)]
struct Info {
#[validate(length(min = 3))]
username: String,
}
/// deserialize `Info` from request's form data
async fn index(info: Form<Info>) -> String {
format!("Welcome {}!", info.username)
}
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> 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