From e2bf50405545eade1e092af0a05af29891efb2ba Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Thu, 4 Jan 2024 04:10:46 +0000 Subject: [PATCH] feat(session): use real async traits (#365) --- .github/workflows/ci.yml | 4 ++-- Cargo.toml | 3 ++- actix-cors/CHANGES.md | 1 + actix-identity/CHANGES.md | 2 ++ actix-protobuf/CHANGES.md | 2 ++ actix-redis/CHANGES.md | 2 ++ actix-session/CHANGES.md | 3 +++ actix-session/Cargo.toml | 5 ++--- actix-session/src/storage/cookie.rs | 5 ++--- actix-session/src/storage/interface.rs | 26 +++++++++++------------- actix-session/src/storage/redis_actor.rs | 1 - actix-session/src/storage/redis_rs.rs | 1 - actix-session/tests/opaque_errors.rs | 1 - actix-settings/CHANGES.md | 2 ++ actix-web-httpauth/CHANGES.md | 2 ++ actix-ws/README.md | 4 ++-- 16 files changed, 36 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4778c326..3d67163ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: target: - { name: Linux, os: ubuntu-latest, triple: x86_64-unknown-linux-gnu } version: - - { name: msrv, version: 1.68.0 } + - { name: msrv, version: 1.75.0 } - { name: stable, version: stable } name: ${{ matrix.target.name }} / ${{ matrix.version.name }} @@ -83,7 +83,7 @@ jobs: - { name: macOS, os: macos-latest, triple: x86_64-apple-darwin } - { name: Windows, os: windows-latest, triple: x86_64-pc-windows-msvc } version: - - { name: msrv, version: 1.68.0 } + - { name: msrv, version: 1.75.0 } - { name: stable, version: stable } name: ${{ matrix.target.name }} / ${{ matrix.version.name }} diff --git a/Cargo.toml b/Cargo.toml index 4793d4ee6..b16e1fa3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,10 @@ members = [ ] [workspace.package] +homepage = "https://actix.rs" license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.68" +rust-version = "1.75" [patch.crates-io] actix-cors = { path = "./actix-cors" } diff --git a/actix-cors/CHANGES.md b/actix-cors/CHANGES.md index 5ad468a63..f0809589d 100644 --- a/actix-cors/CHANGES.md +++ b/actix-cors/CHANGES.md @@ -3,6 +3,7 @@ ## Unreleased - `Cors` is now marked `#[must_use]`. +- Minimum supported Rust version (MSRV) is now 1.75. ## 0.6.5 diff --git a/actix-identity/CHANGES.md b/actix-identity/CHANGES.md index c06efddc4..328ca4d39 100644 --- a/actix-identity/CHANGES.md +++ b/actix-identity/CHANGES.md @@ -2,6 +2,8 @@ ## Unreleased +- Minimum supported Rust version (MSRV) is now 1.75. + ## 0.6.0 - Add `error` module. diff --git a/actix-protobuf/CHANGES.md b/actix-protobuf/CHANGES.md index 996b8c12a..a711f7466 100644 --- a/actix-protobuf/CHANGES.md +++ b/actix-protobuf/CHANGES.md @@ -2,6 +2,8 @@ ## Unreleased +- Minimum supported Rust version (MSRV) is now 1.75. + ## 0.10.0 - Updated `prost` dependency to `0.12`. diff --git a/actix-redis/CHANGES.md b/actix-redis/CHANGES.md index 7bd6b09bd..11dc47d47 100644 --- a/actix-redis/CHANGES.md +++ b/actix-redis/CHANGES.md @@ -2,6 +2,8 @@ ## Unreleased +- Minimum supported Rust version (MSRV) is now 1.75. + ## 0.13.0 - Update `redis-async` dependency to `0.16`. diff --git a/actix-session/CHANGES.md b/actix-session/CHANGES.md index cf840a947..d97f3c6b1 100644 --- a/actix-session/CHANGES.md +++ b/actix-session/CHANGES.md @@ -2,6 +2,9 @@ ## Unreleased +- Remove use of `async-trait` on `SessionStore` trait. +- Minimum supported Rust version (MSRV) is now 1.75. + ## 0.8.0 - Set secure attribute when adding a session removal cookie. diff --git a/actix-session/Cargo.toml b/actix-session/Cargo.toml index 5a956f951..623e1053e 100644 --- a/actix-session/Cargo.toml +++ b/actix-session/Cargo.toml @@ -7,8 +7,8 @@ authors = [ ] description = "Session management for Actix Web" keywords = ["http", "web", "framework", "async", "session"] -homepage = "https://actix.rs" -repository = "https://github.com/actix/actix-extras.git" +repository = "https://github.com/actix/actix-extras/tree/master/actix-session" +homepage.workspace = true license.workspace = true edition.workspace = true rust-version.workspace = true @@ -30,7 +30,6 @@ actix-utils = "3" actix-web = { version = "4", default-features = false, features = ["cookies", "secure-cookies"] } anyhow = "1" -async-trait = "0.1" derive_more = "0.99.7" rand = { version = "0.8", optional = true } serde = { version = "1" } diff --git a/actix-session/src/storage/cookie.rs b/actix-session/src/storage/cookie.rs index e74c13cbb..54e2ec5a9 100644 --- a/actix-session/src/storage/cookie.rs +++ b/actix-session/src/storage/cookie.rs @@ -49,7 +49,6 @@ use crate::storage::{ #[non_exhaustive] pub struct CookieSessionStore; -#[async_trait::async_trait(?Send)] impl SessionStore for CookieSessionStore { async fn load(&self, session_key: &SessionKey) -> Result, LoadError> { serde_json::from_str(session_key.as_ref()) @@ -67,10 +66,10 @@ impl SessionStore for CookieSessionStore { .map_err(anyhow::Error::new) .map_err(SaveError::Serialization)?; - Ok(session_key + session_key .try_into() .map_err(Into::into) - .map_err(SaveError::Other)?) + .map_err(SaveError::Other) } async fn update( diff --git a/actix-session/src/storage/interface.rs b/actix-session/src/storage/interface.rs index 2b52c59ed..7030dbb28 100644 --- a/actix-session/src/storage/interface.rs +++ b/actix-session/src/storage/interface.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::{collections::HashMap, future::Future}; use actix_web::cookie::time::Duration; use derive_more::Display; @@ -10,41 +10,39 @@ pub(crate) type SessionState = HashMap; /// The interface to retrieve and save the current session data from/to the chosen storage backend. /// /// You can provide your own custom session store backend by implementing this trait. -/// -/// [`async-trait`](https://docs.rs/async-trait) is used for this trait's definition. Therefore, it -/// is required for implementations, too. In particular, we use the send-optional variant: -/// `#[async_trait(?Send)]`. -#[async_trait::async_trait(?Send)] pub trait SessionStore { /// Loads the session state associated to a session key. - async fn load(&self, session_key: &SessionKey) -> Result, LoadError>; + fn load( + &self, + session_key: &SessionKey, + ) -> impl Future, LoadError>>; /// Persist the session state for a newly created session. /// /// Returns the corresponding session key. - async fn save( + fn save( &self, session_state: SessionState, ttl: &Duration, - ) -> Result; + ) -> impl Future>; /// Updates the session state associated to a pre-existing session key. - async fn update( + fn update( &self, session_key: SessionKey, session_state: SessionState, ttl: &Duration, - ) -> Result; + ) -> impl Future>; /// Updates the TTL of the session state associated to a pre-existing session key. - async fn update_ttl( + fn update_ttl( &self, session_key: &SessionKey, ttl: &Duration, - ) -> Result<(), anyhow::Error>; + ) -> impl Future>; /// Deletes a session from the store. - async fn delete(&self, session_key: &SessionKey) -> Result<(), anyhow::Error>; + fn delete(&self, session_key: &SessionKey) -> impl Future>; } // We cannot derive the `Error` implementation using `derive_more` for our custom errors: diff --git a/actix-session/src/storage/redis_actor.rs b/actix-session/src/storage/redis_actor.rs index 975df10c9..ae41a42b9 100644 --- a/actix-session/src/storage/redis_actor.rs +++ b/actix-session/src/storage/redis_actor.rs @@ -118,7 +118,6 @@ impl RedisActorSessionStoreBuilder { } } -#[async_trait::async_trait(?Send)] impl SessionStore for RedisActorSessionStore { async fn load(&self, session_key: &SessionKey) -> Result, LoadError> { let cache_key = (self.configuration.cache_keygen)(session_key.as_ref()); diff --git a/actix-session/src/storage/redis_rs.rs b/actix-session/src/storage/redis_rs.rs index 223e99719..b3fde3943 100644 --- a/actix-session/src/storage/redis_rs.rs +++ b/actix-session/src/storage/redis_rs.rs @@ -132,7 +132,6 @@ impl RedisSessionStoreBuilder { } } -#[async_trait::async_trait(?Send)] impl SessionStore for RedisSessionStore { async fn load(&self, session_key: &SessionKey) -> Result, LoadError> { let cache_key = (self.configuration.cache_keygen)(session_key.as_ref()); diff --git a/actix-session/tests/opaque_errors.rs b/actix-session/tests/opaque_errors.rs index 55500c494..ef7d85dfc 100644 --- a/actix-session/tests/opaque_errors.rs +++ b/actix-session/tests/opaque_errors.rs @@ -44,7 +44,6 @@ async fn errors_are_opaque() { struct MockStore; -#[async_trait::async_trait(?Send)] impl SessionStore for MockStore { async fn load( &self, diff --git a/actix-settings/CHANGES.md b/actix-settings/CHANGES.md index 492e44c17..c3a34362e 100644 --- a/actix-settings/CHANGES.md +++ b/actix-settings/CHANGES.md @@ -2,6 +2,8 @@ ## Unreleased +- Minimum supported Rust version (MSRV) is now 1.75. + ## 0.7.1 - Fix doc examples. diff --git a/actix-web-httpauth/CHANGES.md b/actix-web-httpauth/CHANGES.md index b96ca7778..0d298bf3b 100644 --- a/actix-web-httpauth/CHANGES.md +++ b/actix-web-httpauth/CHANGES.md @@ -2,6 +2,8 @@ ## Unreleased +- Minimum supported Rust version (MSRV) is now 1.75. + ## 0.8.1 - Implement `From` for `BasicAuth`. diff --git a/actix-ws/README.md b/actix-ws/README.md index 6117d53a9..558b45e9d 100644 --- a/actix-ws/README.md +++ b/actix-ws/README.md @@ -10,8 +10,8 @@ ## Documentation & Resources - [API Documentation](https://docs.rs/actix-ws) -- [Example Projects](https://github.com/actix/examples/tree/master/websockets) -- Minimum Supported Rust Version (MSRV): 1.68 +- [Example Chat Project](https://github.com/actix/examples/tree/master/websockets/chat-actorless) +- Minimum Supported Rust Version (MSRV): 1.75 ## Usage