From 983dba5014ae4564b9aa0ad9fc557ac84029db6b Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy Date: Mon, 18 Oct 2021 10:05:51 +0300 Subject: [PATCH] fix Send auto-impl --- actix-service/src/apply.rs | 6 ++-- actix-service/src/fn_service.rs | 44 +++++++++++++++++++++++++++--- actix-service/src/map.rs | 4 +-- actix-service/src/map_config.rs | 4 +-- actix-service/src/map_err.rs | 4 +-- actix-service/src/map_init_err.rs | 2 +- actix-service/src/pipeline.rs | 4 +-- actix-service/src/transform_err.rs | 2 +- 8 files changed, 53 insertions(+), 17 deletions(-) diff --git a/actix-service/src/apply.rs b/actix-service/src/apply.rs index 2f798fd0..e03541a1 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 (Req, 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 (Req, In, Res, Err)>, } impl ApplyFactory @@ -171,7 +171,7 @@ pin_project! { #[pin] fut: SF::Future, wrap_fn: Option, - _phantom: PhantomData<(Req, Res)>, + _phantom: PhantomData(Req, Res)>, } } diff --git a/actix-service/src/fn_service.rs b/actix-service/src/fn_service.rs index 8c1a6f51..ffa4f478 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 Req>, } impl FnService @@ -160,7 +160,7 @@ where Fut: Future>, { f: F, - _t: PhantomData<(Req, Cfg)>, + _t: PhantomData (Req, Cfg)>, } impl FnServiceFactory @@ -237,7 +237,7 @@ where Srv: Service, { f: F, - _t: PhantomData<(Fut, Cfg, Req, Srv, Err)>, + _t: PhantomData (Fut, Cfg, Req, Srv, Err)>, } impl FnServiceConfig @@ -293,7 +293,7 @@ where Fut: Future>, { f: F, - _t: PhantomData<(Cfg, Req)>, + _t: PhantomData (Cfg, Req)>, } 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..68d6cb1c 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 (Req, Res)>, } impl Map { @@ -107,7 +107,7 @@ where pub struct MapServiceFactory { a: A, f: F, - r: PhantomData<(Res, Req)>, + r: PhantomData (Res, Req)>, } impl MapServiceFactory { diff --git a/actix-service/src/map_config.rs b/actix-service/src/map_config.rs index 1297f7a0..c51e0031 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 (Cfg, Req)>, } impl MapConfig { @@ -82,7 +82,7 @@ where /// `unit_config()` config combinator pub struct UnitConfig { factory: SF, - _phantom: PhantomData<(Cfg, Req)>, + _phantom: PhantomData (Cfg, Req)>, } impl UnitConfig diff --git a/actix-service/src/map_err.rs b/actix-service/src/map_err.rs index 7b1ac2ab..2f67b1a0 100644 --- a/actix-service/src/map_err.rs +++ b/actix-service/src/map_err.rs @@ -16,7 +16,7 @@ use super::{Service, ServiceFactory}; pub struct MapErr { service: S, f: F, - _t: PhantomData<(E, Req)>, + _t: PhantomData (E, Req)>, } impl MapErr { @@ -112,7 +112,7 @@ where { a: A, f: F, - e: PhantomData<(E, Req)>, + e: PhantomData (E, Req)>, } impl MapErrServiceFactory diff --git a/actix-service/src/map_init_err.rs b/actix-service/src/map_init_err.rs index 9fc383aa..f67612d0 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 (Req, Err)>, } impl MapInitErr diff --git a/actix-service/src/pipeline.rs b/actix-service/src/pipeline.rs index 2c71a74b..e6e6b10c 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 Req>, } impl Pipeline @@ -162,7 +162,7 @@ impl, Req> Service for Pipeline { /// Pipeline factory pub(crate) struct PipelineFactory { factory: SF, - _phantom: PhantomData, + _phantom: PhantomData Req>, } impl PipelineFactory diff --git a/actix-service/src/transform_err.rs b/actix-service/src/transform_err.rs index b4695d5c..64a2a3c1 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, Req, E)>, } impl TransformMapInitErr {