Skip to content

Commit 12df4d7

Browse files
authored
Remove need for paste (#649)
Co-authored-by: Dylan Anthony <[email protected]>
1 parent 6f5b81d commit 12df4d7

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actix-service/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ rust-version.workspace = true
1212

1313
[dependencies]
1414
futures-core = { version = "0.3.17", default-features = false }
15-
paste = "1"
1615
pin-project-lite = "0.2"
1716

1817
[dev-dependencies]

actix-service/src/boxed.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,38 @@
33
use alloc::{boxed::Box, rc::Rc};
44
use core::{future::Future, pin::Pin};
55

6-
use paste::paste;
7-
86
use crate::{Service, ServiceFactory};
97

108
/// A boxed future with no send bound or lifetime parameters.
119
pub type BoxFuture<T> = Pin<Box<dyn Future<Output = T>>>;
1210

13-
macro_rules! service_object {
14-
($name: ident, $type: tt, $fn_name: ident) => {
15-
paste! {
16-
#[doc = "Type alias for service trait object using `" $type "`."]
17-
pub type $name<Req, Res, Err> = $type<
18-
dyn Service<Req, Response = Res, Error = Err, Future = BoxFuture<Result<Res, Err>>>,
19-
>;
20-
21-
#[doc = "Wraps service as a trait object using [`" $name "`]."]
22-
pub fn $fn_name<S, Req>(service: S) -> $name<Req, S::Response, S::Error>
23-
where
24-
S: Service<Req> + 'static,
25-
Req: 'static,
26-
S::Future: 'static,
27-
{
28-
$type::new(ServiceWrapper::new(service))
29-
}
30-
}
31-
};
11+
/// Type alias for service trait object using [`Box`].
12+
pub type BoxService<Req, Res, Err> =
13+
Box<dyn Service<Req, Response = Res, Error = Err, Future = BoxFuture<Result<Res, Err>>>>;
14+
15+
/// Wraps service as a trait object using [`BoxService`].
16+
pub fn service<S, Req>(service: S) -> BoxService<Req, S::Response, S::Error>
17+
where
18+
S: Service<Req> + 'static,
19+
Req: 'static,
20+
S::Future: 'static,
21+
{
22+
Box::new(ServiceWrapper::new(service))
3223
}
3324

34-
service_object!(BoxService, Box, service);
35-
service_object!(RcService, Rc, rc_service);
25+
/// Type alias for service trait object using [`Rc`].
26+
pub type RcService<Req, Res, Err> =
27+
Rc<dyn Service<Req, Response = Res, Error = Err, Future = BoxFuture<Result<Res, Err>>>>;
28+
29+
/// Wraps service as a trait object using [`RcService`].
30+
pub fn rc_service<S, Req>(service: S) -> RcService<Req, S::Response, S::Error>
31+
where
32+
S: Service<Req> + 'static,
33+
Req: 'static,
34+
S::Future: 'static,
35+
{
36+
Rc::new(ServiceWrapper::new(service))
37+
}
3638

3739
struct ServiceWrapper<S> {
3840
inner: S,

0 commit comments

Comments
 (0)