diff --git a/actix-codec/src/framed.rs b/actix-codec/src/framed.rs index 04b8a8f5..6933d28e 100644 --- a/actix-codec/src/framed.rs +++ b/actix-codec/src/framed.rs @@ -1,10 +1,14 @@ -use std::pin::Pin; -use std::task::{Context, Poll}; -use std::{fmt, io}; +use std::{ + fmt, io, + pin::Pin, + task::{Context, Poll}, +}; +use bitflags::bitflags; use bytes::{Buf, BytesMut}; use futures_core::{ready, Stream}; use futures_sink::Sink; +use pin_project_lite::pin_project; use crate::{AsyncRead, AsyncWrite, Decoder, Encoder}; @@ -13,14 +17,14 @@ const LW: usize = 1024; /// High-water mark const HW: usize = 8 * 1024; -bitflags::bitflags! { +bitflags! { struct Flags: u8 { const EOF = 0b0001; const READABLE = 0b0010; } } -pin_project_lite::pin_project! { +pin_project! { /// A unified `Stream` and `Sink` interface to an underlying I/O object, using the `Encoder` and /// `Decoder` traits to encode and decode frames. /// diff --git a/actix-service/CHANGES.md b/actix-service/CHANGES.md index c87e2470..bc7e69df 100644 --- a/actix-service/CHANGES.md +++ b/actix-service/CHANGES.md @@ -1,6 +1,9 @@ # Changes ## Unreleased - 2021-xx-xx +* Service types can now be `Send` and `'static` regardless of request, response, and config types, etc.. [#397] + +[#397]: https://github.com/actix/actix-net/pull/397 ## 2.0.1 - 2021-10-11 diff --git a/actix-service/src/apply.rs b/actix-service/src/apply.rs index 2f798fd0..c77f4242 100644 --- a/actix-service/src/apply.rs +++ b/actix-service/src/apply.rs @@ -51,7 +51,7 @@ where { service: S, wrap_fn: F, - _phantom: PhantomData<(Req, In, Res, Err)>, + _phantom: PhantomData (In, Res, Err)>, } impl Apply @@ -106,7 +106,7 @@ where pub struct ApplyFactory { factory: SF, wrap_fn: F, - _phantom: PhantomData<(Req, In, Res, Err)>, + _phantom: PhantomData (In, Res, Err)>, } impl ApplyFactory @@ -171,7 +171,7 @@ pin_project! { #[pin] fut: SF::Future, wrap_fn: Option, - _phantom: PhantomData<(Req, Res)>, + _phantom: PhantomData Res>, } } diff --git a/actix-service/src/fn_service.rs b/actix-service/src/fn_service.rs index f83ef81f..ae22e39b 100644 --- a/actix-service/src/fn_service.rs +++ b/actix-service/src/fn_service.rs @@ -105,7 +105,7 @@ where Fut: Future>, { f: F, - _t: PhantomData, + _t: PhantomData, } impl FnService @@ -160,7 +160,7 @@ where Fut: Future>, { f: F, - _t: PhantomData<(Req, Cfg)>, + _t: PhantomData, } impl FnServiceFactory @@ -237,7 +237,7 @@ where Srv: Service, { f: F, - _t: PhantomData<(Fut, Cfg, Req, Srv, Err)>, + _t: PhantomData (Fut, Srv, Err)>, } impl FnServiceConfig @@ -293,7 +293,7 @@ where Fut: Future>, { f: F, - _t: PhantomData<(Cfg, Req)>, + _t: PhantomData, } impl FnServiceNoConfig @@ -391,4 +391,40 @@ mod tests { assert!(res.is_ok()); assert_eq!(res.unwrap(), ("srv", 1)); } + + #[actix_rt::test] + async fn test_auto_impl_send() { + use crate::{map_config, ServiceExt, ServiceFactoryExt}; + use alloc::rc::Rc; + + let srv_1 = fn_service(|_: Rc| ok::<_, Rc>(Rc::new(0u8))); + + let fac_1 = fn_factory_with_config(|_: Rc| { + ok::<_, Rc>(fn_service(|_: Rc| ok::<_, Rc>(Rc::new(0u8)))) + }); + + let fac_2 = fn_factory(|| { + ok::<_, Rc>(fn_service(|_: Rc| ok::<_, Rc>(Rc::new(0u8)))) + }); + + fn is_send(_: &T) {} + + is_send(&fac_1); + is_send(&map_config(fac_1.clone(), |_: Rc| Rc::new(0u8))); + is_send(&fac_1.clone().map_err(|_| Rc::new(0u8))); + is_send(&fac_1.clone().map(|_| Rc::new(0u8))); + is_send(&fac_1.clone().map_init_err(|_| Rc::new(0u8))); + // `and_then` is always !Send + // is_send(&fac_1.clone().and_then(fac_1.clone())); + is_send(&fac_1.new_service(Rc::new(0u8)).await.unwrap()); + + is_send(&fac_2); + is_send(&fac_2.new_service(Rc::new(0u8)).await.unwrap()); + + is_send(&srv_1); + is_send(&ServiceExt::map(srv_1.clone(), |_| Rc::new(0u8))); + is_send(&ServiceExt::map_err(srv_1.clone(), |_| Rc::new(0u8))); + // `and_then` is always !Send + // is_send(&ServiceExt::and_then(srv_1.clone(), srv_1.clone())); + } } diff --git a/actix-service/src/map.rs b/actix-service/src/map.rs index 12fd4395..985a5433 100644 --- a/actix-service/src/map.rs +++ b/actix-service/src/map.rs @@ -15,7 +15,7 @@ use super::{Service, ServiceFactory}; pub struct Map { service: A, f: F, - _t: PhantomData<(Req, Res)>, + _t: PhantomData Res>, } impl Map { @@ -107,7 +107,7 @@ where pub struct MapServiceFactory { a: A, f: F, - r: PhantomData<(Res, Req)>, + r: PhantomData Res>, } impl MapServiceFactory { diff --git a/actix-service/src/map_config.rs b/actix-service/src/map_config.rs index 1297f7a0..5b63e3ad 100644 --- a/actix-service/src/map_config.rs +++ b/actix-service/src/map_config.rs @@ -28,7 +28,7 @@ where pub struct MapConfig { factory: SF, cfg_mapper: F, - e: PhantomData<(Cfg, Req)>, + e: PhantomData, } impl MapConfig { @@ -82,7 +82,7 @@ where /// `unit_config()` config combinator pub struct UnitConfig { factory: SF, - _phantom: PhantomData<(Cfg, Req)>, + _phantom: PhantomData, } impl UnitConfig diff --git a/actix-service/src/map_err.rs b/actix-service/src/map_err.rs index aad0f421..3ce6f418 100644 --- a/actix-service/src/map_err.rs +++ b/actix-service/src/map_err.rs @@ -15,7 +15,7 @@ use super::{Service, ServiceFactory}; pub struct MapErr { service: S, mapper: F, - _t: PhantomData<(E, Req)>, + _t: PhantomData E>, } impl MapErr { @@ -111,7 +111,7 @@ where { a: SF, f: F, - e: PhantomData<(E, Req)>, + e: PhantomData E>, } impl MapErrServiceFactory diff --git a/actix-service/src/map_init_err.rs b/actix-service/src/map_init_err.rs index 9fc383aa..a8a22a78 100644 --- a/actix-service/src/map_init_err.rs +++ b/actix-service/src/map_init_err.rs @@ -13,7 +13,7 @@ use super::ServiceFactory; pub struct MapInitErr { a: A, f: F, - e: PhantomData<(Req, Err)>, + e: PhantomData Err>, } impl MapInitErr diff --git a/actix-service/src/pipeline.rs b/actix-service/src/pipeline.rs index 2c71a74b..2617d0ed 100644 --- a/actix-service/src/pipeline.rs +++ b/actix-service/src/pipeline.rs @@ -40,7 +40,7 @@ where /// Pipeline service - pipeline allows to compose multiple service into one service. pub(crate) struct Pipeline { service: S, - _phantom: PhantomData, + _phantom: PhantomData, } impl Pipeline @@ -162,7 +162,7 @@ impl, Req> Service for Pipeline { /// Pipeline factory pub(crate) struct PipelineFactory { factory: SF, - _phantom: PhantomData, + _phantom: PhantomData, } impl PipelineFactory diff --git a/actix-service/src/transform_err.rs b/actix-service/src/transform_err.rs index b4695d5c..b6225a38 100644 --- a/actix-service/src/transform_err.rs +++ b/actix-service/src/transform_err.rs @@ -14,7 +14,7 @@ use super::Transform; pub struct TransformMapInitErr { transform: T, mapper: F, - _phantom: PhantomData<(S, Req, E)>, + _phantom: PhantomData (S, E)>, } impl TransformMapInitErr { diff --git a/actix-tls/CHANGES.md b/actix-tls/CHANGES.md index 709dfcc6..0ecc676e 100644 --- a/actix-tls/CHANGES.md +++ b/actix-tls/CHANGES.md @@ -38,36 +38,6 @@ [#423]: https://github.com/actix/actix-net/pull/423 -### Added -* Derive `Debug` for `connect::Connection`. [#422] -* Implement `Display` for `accept::TlsError`. [#422] -* Implement `Error` for `accept::TlsError` where both types also implement `Error`. [#422] -* Implement `Default` for `connect::Resolver`. [#422] -* Implement `Error` for `connect::ConnectError`. [#422] - -### Changed -* The crate's default features flags no longer include `uri`. [#422] -* Useful re-exports from underlying TLS crates are exposed in a `reexports` modules in all acceptors and connectors. -* Convert `connect::ResolverService` from enum to struct. [#422] -* Make `ConnectAddrsIter` private. [#422] -* Rename `accept::native_tls::{NativeTlsAcceptorService => AcceptorService}`. [#422] -* Rename `connect::{Address => Host}` trait. [#422] -* Rename method `connect::Connection::{host => hostname}`. [#422] -* Rename struct `connect::{Connect => ConnectInfo}`. [#422] -* Rename struct `connect::{ConnectService => ConnectorService}`. [#422] -* Rename struct `connect::{ConnectServiceFactory => Connector}`. [#422] -* Rename TLS acceptor service future types and hide from docs. [#422] -* Unbox some service futures types. [#422] -* Inline modules in `connect::tls` to `connect` module. [#422] - -### Removed -* Remove `connect::{new_connector, new_connector_factory, default_connector, default_connector_factory}` methods. [#422] -* Remove `connect::native_tls::Connector::service` method. [#422] -* Remove redundant `connect::Connection::from_parts` method. [#422] - -[#422]: https://github.com/actix/actix-net/pull/422 - - ## 3.0.0-beta.9 - 2021-11-22 * Add configurable timeout for accepting TLS connection. [#393] * Added `TlsError::Timeout` variant. [#393]