From 50a195e9ce9d8deb7df550164843d97595cf85bd Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Sun, 28 Feb 2021 11:42:11 -0800 Subject: [PATCH] add impl Service for Rc (#288) --- actix-service/src/lib.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/actix-service/src/lib.rs b/actix-service/src/lib.rs index e591eb51..66132961 100644 --- a/actix-service/src/lib.rs +++ b/actix-service/src/lib.rs @@ -150,6 +150,7 @@ pub trait ServiceFactory { fn new_service(&self, cfg: Self::Config) -> Self::Future; } +// TODO: remove implement on mut reference. impl<'a, S, Req> Service for &'a mut S where S: Service + 'a, @@ -167,6 +168,23 @@ where } } +impl<'a, S, Req> Service for &'a S +where + S: Service + 'a, +{ + type Response = S::Response; + type Error = S::Error; + type Future = S::Future; + + fn poll_ready(&self, ctx: &mut Context<'_>) -> Poll> { + (**self).poll_ready(ctx) + } + + fn call(&self, request: Req) -> S::Future { + (**self).call(request) + } +} + impl Service for Box where S: Service + ?Sized, @@ -184,7 +202,7 @@ where } } -impl Service for RefCell +impl Service for Rc where S: Service, { @@ -193,15 +211,15 @@ where type Future = S::Future; fn poll_ready(&self, ctx: &mut Context<'_>) -> Poll> { - self.borrow().poll_ready(ctx) + (&**self).poll_ready(ctx) } fn call(&self, request: Req) -> S::Future { - self.borrow().call(request) + (&**self).call(request) } } -impl Service for Rc> +impl Service for RefCell where S: Service, {