1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-23 21:51:06 +01:00

add impl Service for Rc<S: Service> (#288)

This commit is contained in:
fakeshadow 2021-02-28 11:42:11 -08:00 committed by GitHub
parent 06ddad0051
commit 50a195e9ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -150,6 +150,7 @@ pub trait ServiceFactory<Req> {
fn new_service(&self, cfg: Self::Config) -> Self::Future; fn new_service(&self, cfg: Self::Config) -> Self::Future;
} }
// TODO: remove implement on mut reference.
impl<'a, S, Req> Service<Req> for &'a mut S impl<'a, S, Req> Service<Req> for &'a mut S
where where
S: Service<Req> + 'a, S: Service<Req> + 'a,
@ -167,6 +168,23 @@ where
} }
} }
impl<'a, S, Req> Service<Req> for &'a S
where
S: Service<Req> + 'a,
{
type Response = S::Response;
type Error = S::Error;
type Future = S::Future;
fn poll_ready(&self, ctx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
(**self).poll_ready(ctx)
}
fn call(&self, request: Req) -> S::Future {
(**self).call(request)
}
}
impl<S, Req> Service<Req> for Box<S> impl<S, Req> Service<Req> for Box<S>
where where
S: Service<Req> + ?Sized, S: Service<Req> + ?Sized,
@ -184,7 +202,7 @@ where
} }
} }
impl<S, Req> Service<Req> for RefCell<S> impl<S, Req> Service<Req> for Rc<S>
where where
S: Service<Req>, S: Service<Req>,
{ {
@ -193,15 +211,15 @@ where
type Future = S::Future; type Future = S::Future;
fn poll_ready(&self, ctx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { fn poll_ready(&self, ctx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.borrow().poll_ready(ctx) (&**self).poll_ready(ctx)
} }
fn call(&self, request: Req) -> S::Future { fn call(&self, request: Req) -> S::Future {
self.borrow().call(request) (&**self).call(request)
} }
} }
impl<S, Req> Service<Req> for Rc<RefCell<S>> impl<S, Req> Service<Req> for RefCell<S>
where where
S: Service<Req>, S: Service<Req>,
{ {