From 77cb6730f9265591dad141f4f9b840069c9cd2b9 Mon Sep 17 00:00:00 2001 From: Sam Scott Date: Wed, 3 Jun 2020 10:26:45 -0400 Subject: Support actix-web v2 (#30) * update dependencies - actix-web v2 - percent encoding v2.1 - rust 2018 edition - remove rustfmt no longer supported rules * ci: add feature build matrix * fix actix unit tests Co-authored-by: Mario Reder --- src/actix.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/actix.rs') diff --git a/src/actix.rs b/src/actix.rs index fa7e105..70dc6e1 100644 --- a/src/actix.rs +++ b/src/actix.rs @@ -2,12 +2,14 @@ //! //! Enable with the `actix` feature. +use crate::de::Config as QsConfig; +use crate::error::Error as QsError; + use actix_web::dev::Payload; use actix_web::{ Error as ActixError, FromRequest, HttpRequest, HttpResponse, ResponseError, }; -use de::Config as QsConfig; -use error::Error as QsError; +use futures::future::{ready, Ready}; use serde::de; use std::fmt; use std::fmt::{Debug, Display}; @@ -28,7 +30,7 @@ impl ResponseError for QsError { /// ```rust /// #[macro_use] extern crate serde_derive; /// extern crate actix_web; -/// use actix_web::{web, App}; +/// use actix_web::{web, App, HttpResponse}; /// use serde_qs::actix::QsQuery; /// /// #[derive(Deserialize)] @@ -38,7 +40,7 @@ impl ResponseError for QsError { /// /// // Use `QsQuery` extractor for query information. /// // The correct request for this handler would be `/users?id[]=1124&id[]=88"` -/// fn filter_users(info: QsQuery) -> String { +/// fn filter_users(info: QsQuery) -> HttpResponse { /// info.id.iter().map(|i| i.to_string()).collect::>().join(", ").into() /// } /// @@ -88,7 +90,7 @@ where T: de::DeserializeOwned, { type Error = ActixError; - type Future = Result; + type Future = Ready>; type Config = QsQueryConfig; #[inline] @@ -103,7 +105,7 @@ where .map(|c| &c.qs_config) .unwrap_or(&default_qsconfig); - qsconfig + let res = qsconfig .deserialize_str::(req.query_string()) .map(|val| Ok(QsQuery(val))) .unwrap_or_else(move |e| { @@ -114,7 +116,8 @@ where }; Err(e) - }) + }); + ready(res) } } @@ -133,13 +136,13 @@ where /// } /// /// /// deserialize `Info` from request's querystring -/// fn index(info: QsQuery) -> String { -/// format!("Welcome {}!", info.username) +/// fn index(info: QsQuery) -> HttpResponse { +/// format!("Welcome {}!", info.username).into() /// } /// /// fn main() { /// let app = App::new().service( -/// web::resource("/index.html").data( +/// web::resource("/index.html").app_data( /// // change query extractor configuration /// QsQuery::::configure(|cfg| { /// cfg.error_handler(|err, req| { // <- create custom error response @@ -155,7 +158,7 @@ where pub struct QsQueryConfig { ehandler: - Option ActixError + Send + Sync>>, + Option ActixError + Send + Sync>>, qs_config: QsConfig, } -- cgit v1.2.3