pub struct QueryConfig {
pub ehandler: Option<Arc<dyn Fn(Error, &HttpRequest) -> Error + Send + Sync>>,
}
Expand description
Query extractor configuration.
§Example
use actix_web::{error, web, App, FromRequest, HttpResponse};
use serde::Deserialize;
use actix_web_validator::{Query, QueryConfig};
use validator::Validate;
#[derive(Deserialize, Validate)]
struct Info {
#[validate(length(min = 1))]
username: String,
}
/// deserialize `Info` from request's querystring
async fn index(info: Query<Info>) -> String {
format!("Welcome {}!", info.username)
}
fn main() {
let query_config = QueryConfig::default()
.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(query_config)
.route(web::post().to(index))
);
}
Fields§
§ehandler: Option<Arc<dyn Fn(Error, &HttpRequest) -> Error + Send + Sync>>
Implementations§
Source§impl QueryConfig
impl QueryConfig
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 QueryConfig
impl Clone for QueryConfig
Source§fn clone(&self) -> QueryConfig
fn clone(&self) -> QueryConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Default for QueryConfig
impl Default for QueryConfig
Source§fn default() -> QueryConfig
fn default() -> QueryConfig
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for QueryConfig
impl !RefUnwindSafe for QueryConfig
impl Send for QueryConfig
impl Sync for QueryConfig
impl Unpin for QueryConfig
impl !UnwindSafe for QueryConfig
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