Struct actix_web::dev::QueryConfig
source · pub struct QueryConfig<S> { /* private fields */ }
Expand description
Query extractor configuration
#[macro_use] extern crate serde_derive;
use actix_web::{error, http, App, HttpResponse, Query, Result};
#[derive(Deserialize)]
struct Info {
username: String,
}
/// deserialize `Info` from request's body, max payload size is 4kb
fn index(info: Query<Info>) -> Result<String> {
Ok(format!("Welcome {}!", info.username))
}
fn main() {
let app = App::new().resource("/index.html", |r| {
r.method(http::Method::GET).with_config(index, |cfg| {
cfg.0.error_handler(|err, req| {
// <- create custom error response
error::InternalError::from_response(err, HttpResponse::Conflict().finish()).into()
});
})
});
}
Implementations
sourceimpl<S> QueryConfig<S>
impl<S> QueryConfig<S>
sourcepub fn error_handler<F>(&mut self, f: F) -> &mut Selfwhere
F: Fn(Error, &HttpRequest<S>) -> Error + 'static,
pub fn error_handler<F>(&mut self, f: F) -> &mut Selfwhere
F: Fn(Error, &HttpRequest<S>) -> Error + 'static,
Set custom error handler
Trait Implementations
Auto Trait Implementations
impl<S> !RefUnwindSafe for QueryConfig<S>
impl<S> !Send for QueryConfig<S>
impl<S> !Sync for QueryConfig<S>
impl<S> Unpin for QueryConfig<S>
impl<S> !UnwindSafe for QueryConfig<S>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more