diff --git a/Cargo.lock b/Cargo.lock index 30f79e5d..d884859a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,7 +69,6 @@ dependencies = [ "actix-utils", "futures-core", "futures-util", - "paste", "pin-project-lite", ] diff --git a/actix-service/Cargo.toml b/actix-service/Cargo.toml index f0be441b..64273943 100644 --- a/actix-service/Cargo.toml +++ b/actix-service/Cargo.toml @@ -12,7 +12,6 @@ rust-version.workspace = true [dependencies] futures-core = { version = "0.3.17", default-features = false } -paste = "1" pin-project-lite = "0.2" [dev-dependencies] diff --git a/actix-service/src/boxed.rs b/actix-service/src/boxed.rs index cc9ad410..e3f7a80b 100644 --- a/actix-service/src/boxed.rs +++ b/actix-service/src/boxed.rs @@ -3,36 +3,38 @@ use alloc::{boxed::Box, rc::Rc}; use core::{future::Future, pin::Pin}; -use paste::paste; - use crate::{Service, ServiceFactory}; /// A boxed future with no send bound or lifetime parameters. pub type BoxFuture = Pin>>; -macro_rules! service_object { - ($name: ident, $type: tt, $fn_name: ident) => { - paste! { - #[doc = "Type alias for service trait object using `" $type "`."] - pub type $name = $type< - dyn Service>>, - >; +/// Type alias for service trait object using [`Box`]. +pub type BoxService = + Box>>>; - #[doc = "Wraps service as a trait object using [`" $name "`]."] - pub fn $fn_name(service: S) -> $name - where - S: Service + 'static, - Req: 'static, - S::Future: 'static, - { - $type::new(ServiceWrapper::new(service)) - } - } - }; +/// Wraps service as a trait object using [`BoxService`]. +pub fn service(service: S) -> BoxService +where + S: Service + 'static, + Req: 'static, + S::Future: 'static, +{ + Box::new(ServiceWrapper::new(service)) } -service_object!(BoxService, Box, service); -service_object!(RcService, Rc, rc_service); +/// Type alias for service trait object using [`Rc`]. +pub type RcService = + Rc>>>; + +/// Wraps service as a trait object using [`RcService`]. +pub fn rc_service(service: S) -> RcService +where + S: Service + 'static, + Req: 'static, + S::Future: 'static, +{ + Rc::new(ServiceWrapper::new(service)) +} struct ServiceWrapper { inner: S,