mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-23 22:51:07 +01:00
cleanup clonable service
This commit is contained in:
parent
8108f19580
commit
a16ad6b2cd
@ -57,7 +57,7 @@ tokio-tcp = "0.1"
|
||||
tokio-timer = "0.2"
|
||||
tokio-reactor = "0.1"
|
||||
tokio-current-thread = "0.1"
|
||||
tower-service = { path="../../actix/tower/tower-service/" }
|
||||
tower-service = { git = "https://github.com/tower-rs/tower.git" }
|
||||
trust-dns-proto = "^0.5.0"
|
||||
trust-dns-resolver = "^0.10.0"
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
use std::marker::PhantomData;
|
||||
use std::rc::Rc;
|
||||
|
||||
use futures::Poll;
|
||||
|
||||
@ -6,13 +7,16 @@ use super::cell::Cell;
|
||||
use super::service::Service;
|
||||
|
||||
/// Service that allows to turn non-clone service to a service with `Clone` impl
|
||||
pub struct CloneableService<S: Service<R> + 'static, R> {
|
||||
service: Cell<S>,
|
||||
_t: PhantomData<R>,
|
||||
pub struct CloneableService<T: 'static> {
|
||||
service: Cell<T>,
|
||||
_t: PhantomData<Rc<()>>,
|
||||
}
|
||||
|
||||
impl<S: Service<R> + 'static, R> CloneableService<S, R> {
|
||||
pub fn new(service: S) -> Self {
|
||||
impl<T: 'static> CloneableService<T> {
|
||||
pub fn new<Request>(service: T) -> Self
|
||||
where
|
||||
T: Service<Request>,
|
||||
{
|
||||
Self {
|
||||
service: Cell::new(service),
|
||||
_t: PhantomData,
|
||||
@ -20,7 +24,7 @@ impl<S: Service<R> + 'static, R> CloneableService<S, R> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Service<R> + 'static, R> Clone for CloneableService<S, R> {
|
||||
impl<T: 'static> Clone for CloneableService<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
service: self.service.clone(),
|
||||
@ -29,16 +33,19 @@ impl<S: Service<R> + 'static, R> Clone for CloneableService<S, R> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Service<R> + 'static, R> Service<R> for CloneableService<S, R> {
|
||||
type Response = S::Response;
|
||||
type Error = S::Error;
|
||||
type Future = S::Future;
|
||||
impl<T: 'static, Request> Service<Request> for CloneableService<T>
|
||||
where
|
||||
T: Service<Request>,
|
||||
{
|
||||
type Response = T::Response;
|
||||
type Error = T::Error;
|
||||
type Future = T::Future;
|
||||
|
||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||
self.service.borrow_mut().poll_ready()
|
||||
}
|
||||
|
||||
fn call(&mut self, req: R) -> Self::Future {
|
||||
fn call(&mut self, req: Request) -> Self::Future {
|
||||
self.service.borrow_mut().call(req)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user