pub struct FormConfig { /* private fields */ }
Expand description
Form extractor configuration
use actix_web::{error, web, App, FromRequest, HttpResponse};
use serde::Deserialize;
use actix_web_validator::{Form, FormConfig};
use validator::Validate;
#[derive(Deserialize, Validate)]
struct Info {
#[validate(length(min = 3))]
username: String,
}
/// deserialize `Info` from request's form data, max payload size is 4kb
async fn index(info: Form<Info>) -> String {
format!("Welcome {}!", info.username)
}
fn main() {
let form_config = FormConfig::default()
.limit(4096)
.error_handler(|err, req| { // <- create custom error response
error::InternalError::from_response(err, HttpResponse::Conflict().finish()).into()
});
let app = App::new().service(
web::resource("/index.html")
.app_data(form_config)
.route(web::post().to(index))
);
}
Implementations§
Source§impl FormConfig
impl FormConfig
Sourcepub fn limit(self, limit: usize) -> Self
pub fn limit(self, limit: usize) -> Self
Change max size of payload. By default max size is 16Kb
Sourcepub fn error_handler<F>(self, f: F) -> Self
pub fn error_handler<F>(self, f: F) -> Self
Set custom error handler
Trait Implementations§
Source§impl Clone for FormConfig
impl Clone for FormConfig
Source§fn clone(&self) -> FormConfig
fn clone(&self) -> FormConfig
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for FormConfig
impl !RefUnwindSafe for FormConfig
impl !Send for FormConfig
impl !Sync for FormConfig
impl Unpin for FormConfig
impl !UnwindSafe for FormConfig
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