From f5d720c924f0644e3e3393ebf985eb8cad7079c6 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Mon, 1 Mar 2021 03:25:03 +0800 Subject: [PATCH] add impl Service for Rc --- 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, {