diff options
author | Omid Rad <omid@users.noreply.github.com> | 2022-03-05 23:11:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-05 17:11:59 -0500 |
commit | d4c2caa53736ada8cd78e256fb95019b79e74bf7 (patch) | |
tree | 38950f972c074b8106c9306f57246e5bdd723b07 | |
parent | 7addf2f16ad68988e2125677de931b1bade2f9d1 (diff) |
Actix 4 (#56)
* Remove all default actix features
* Set MSRV
* Have `actix4` feature, instead of `actix`
* enable actix tests for all features
-rw-r--r-- | .github/workflows/ci.yml | 12 | ||||
-rw-r--r-- | Cargo.toml | 11 | ||||
-rw-r--r-- | src/actix.rs | 61 | ||||
-rw-r--r-- | src/lib.rs | 8 | ||||
-rw-r--r-- | tests/test_actix.rs | 7 |
5 files changed, 68 insertions, 31 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 94f5aca..0a1c937 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,5 +53,13 @@ jobs: with: profile: minimal toolchain: stable - - name: Run test - run: cargo test --all-targets --features actix + - name: Run test actix4 + run: cargo test --all-targets --features actix4 + - name: Run test actix3 + run: cargo test --all-targets --features actix3 + - name: Run test actix2 + run: cargo test --all-targets --features actix2 + - name: Run test warp + run: cargo test --all-targets --features warp + - name: Run test no feature + run: cargo test --all-targets @@ -10,10 +10,12 @@ name = "serde_qs" repository = "https://github.com/samscott89/serde_qs" readme = "README.md" version = "0.8.5" +rust-version = "1.36" [dependencies] -actix-web = { version = "3.3", optional = true, package = "actix-web", default-features = false } -actix-web2 = { package = "actix-web", version = "2.0", optional = true, default-features = false } +actix-web4 = { version = "4.0", optional = true, package = "actix-web", default-features = false } +actix-web3 = { version = "3.3", optional = true, package = "actix-web", default-features = false } +actix-web2 = { version = "2.0", optional = true, package = "actix-web", default-features = false } futures = { version = "0.3", optional = true } percent-encoding = "2.1" serde = "1.0" @@ -30,9 +32,10 @@ serde_with = "1.10" [features] default = [] -actix = ["actix-web", "futures"] +actix4 = ["actix-web4", "futures"] +actix3 = ["actix-web3", "futures"] actix2 = ["actix-web2", "futures"] warp = ["futures", "tracing", "warp-framework"] [package.metadata.docs.rs] -features = ["actix", "warp"] +features = ["actix4", "warp"] diff --git a/src/actix.rs b/src/actix.rs index d29d6c9..a522a68 100644 --- a/src/actix.rs +++ b/src/actix.rs @@ -1,17 +1,21 @@ //! Functionality for using `serde_qs` with `actix_web`. //! -//! Enable with the `actix` feature. +//! Enable with the `actix4`, `actix3` or `actix2` features. use crate::de::Config as QsConfig; use crate::error::Error as QsError; -#[cfg(feature = "actix")] -use actix_web; #[cfg(feature = "actix2")] use actix_web2 as actix_web; +#[cfg(feature = "actix3")] +use actix_web3 as actix_web; +#[cfg(feature = "actix4")] +use actix_web4 as actix_web; use actix_web::dev::Payload; -use actix_web::{Error as ActixError, FromRequest, HttpRequest, HttpResponse, ResponseError}; +#[cfg(any(feature = "actix2", feature = "actix3"))] +use actix_web::HttpResponse; +use actix_web::{Error as ActixError, FromRequest, HttpRequest, ResponseError}; use futures::future::{ready, Ready}; use serde::de; use std::fmt; @@ -19,12 +23,20 @@ use std::fmt::{Debug, Display}; use std::ops::{Deref, DerefMut}; use std::sync::Arc; +#[cfg(any(feature = "actix2", feature = "actix3"))] impl ResponseError for QsError { fn error_response(&self) -> HttpResponse { HttpResponse::BadRequest().finish() } } +#[cfg(feature = "actix4")] +impl ResponseError for QsError { + fn status_code(&self) -> actix_web::http::StatusCode { + actix_web::http::StatusCode::BAD_REQUEST + } +} + #[derive(PartialEq, Eq, PartialOrd, Ord)] /// Extract typed information from from the request's query. /// @@ -32,8 +44,10 @@ impl ResponseError for QsError { /// /// ```rust /// # #[macro_use] extern crate serde_derive; -/// # #[cfg(feature = "actix")] -/// # use actix_web; +/// # #[cfg(feature = "actix4")] +/// # use actix_web4 as actix_web; +/// # #[cfg(feature = "actix3")] +/// # use actix_web3 as actix_web; /// # #[cfg(feature = "actix2")] /// # use actix_web2 as actix_web; /// use actix_web::{web, App, HttpResponse}; @@ -47,7 +61,9 @@ 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<UsersFilter>) -> HttpResponse { -/// info.id.iter().map(|i| i.to_string()).collect::<Vec<String>>().join(", ").into() +/// HttpResponse::Ok().body( +/// info.id.iter().map(|i| i.to_string()).collect::<Vec<String>>().join(", ") +/// ) /// } /// /// fn main() { @@ -97,6 +113,7 @@ where { type Error = ActixError; type Future = Ready<Result<Self, ActixError>>; + #[cfg(any(feature = "actix2", feature = "actix3"))] type Config = QsQueryConfig; #[inline] @@ -130,13 +147,16 @@ where /// /// ```rust /// # #[macro_use] extern crate serde_derive; -/// # #[cfg(feature = "actix")] -/// # use actix_web; +/// # #[cfg(feature = "actix4")] +/// # use actix_web4 as actix_web; +/// # #[cfg(feature = "actix3")] +/// # use actix_web3 as actix_web; /// # #[cfg(feature = "actix2")] /// # use actix_web2 as actix_web; /// use actix_web::{error, web, App, FromRequest, HttpResponse}; /// use serde_qs::actix::QsQuery; /// use serde_qs::Config as QsConfig; +/// use serde_qs::actix::QsQueryConfig; /// /// #[derive(Deserialize)] /// struct Info { @@ -145,20 +165,21 @@ where /// /// /// deserialize `Info` from request's querystring /// fn index(info: QsQuery<Info>) -> HttpResponse { -/// format!("Welcome {}!", info.username).into() +/// HttpResponse::Ok().body( +/// format!("Welcome {}!", info.username) +/// ) /// } /// /// fn main() { -/// let app = App::new().service( -/// web::resource("/index.html").app_data( -/// // change query extractor configuration -/// QsQuery::<Info>::configure(|cfg| { -/// cfg.error_handler(|err, req| { // <- create custom error response -/// error::InternalError::from_response( -/// err, HttpResponse::Conflict().finish()).into() -/// }) -/// .qs_config(QsConfig::default()) -/// })) +/// let qs_config = QsQueryConfig::default() +/// .error_handler(|err, req| { // <- create custom error response +/// error::InternalError::from_response( +/// err, HttpResponse::Conflict().finish()).into() +/// }) +/// .qs_config(QsConfig::default()); +/// +/// let app = App::new().service( +/// web::resource("/index.html").app_data(qs_config) /// .route(web::post().to(index)) /// ); /// } @@ -142,7 +142,7 @@ //! //! ## Use with `actix_web` extractors //! -//! The `actix` feature enables the use of `serde_qs::actix::QsQuery`, which +//! The `actix4`, `actix3` or `actix2` features enable the use of `serde_qs::actix::QsQuery`, which //! is a direct substitute for the `actix_web::Query` and can be used as an extractor: //! //! ```ignore @@ -151,7 +151,9 @@ //! } //! ``` //! -//! Support for `actix-web 2.0.0` is available via the `actix2` feature. +//! Support for `actix-web 4.0` is available via the `actix4` feature. +//! Support for `actix-web 3.0` is available via the `actix3` feature. +//! Support for `actix-web 2.0` is available via the `actix2` feature. //! //! ## Use with `warp` filters //! @@ -170,7 +172,7 @@ #[macro_use] extern crate serde; -#[cfg(any(feature = "actix", feature = "actix2"))] +#[cfg(any(feature = "actix4", feature = "actix3", feature = "actix2"))] pub mod actix; mod de; mod error; diff --git a/tests/test_actix.rs b/tests/test_actix.rs index 062cf0c..5159977 100644 --- a/tests/test_actix.rs +++ b/tests/test_actix.rs @@ -1,6 +1,9 @@ -#![cfg(feature = "actix")] +#![cfg(any(feature = "actix4", feature = "actix3", feature = "actix2"))] -extern crate actix_web; +#[cfg(feature = "actix3")] +extern crate actix_web3 as actix_web; +#[cfg(feature = "actix4")] +extern crate actix_web4 as actix_web; extern crate serde; #[macro_use] |