Skip to content

Commit

Permalink
feat(service): implement Service for reference types (#3607)
Browse files Browse the repository at this point in the history
  • Loading branch information
lperlaki committed May 27, 2024
1 parent 3b858ed commit eade122
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,58 @@ pub trait Service<Request> {
/// The discussion on this is here: <https://github.com/hyperium/hyper/issues/3040>
fn call(&self, req: Request) -> Self::Future;
}

impl<Request, S: Service<Request> + ?Sized> Service<Request> for &'_ S {
type Response = S::Response;
type Error = S::Error;
type Future = S::Future;

#[inline]
fn call(&self, req: Request) -> Self::Future {
(**self).call(req)
}
}

impl<Request, S: Service<Request> + ?Sized> Service<Request> for &'_ mut S {
type Response = S::Response;
type Error = S::Error;
type Future = S::Future;

#[inline]
fn call(&self, req: Request) -> Self::Future {
(**self).call(req)
}
}

impl<Request, S: Service<Request> + ?Sized> Service<Request> for Box<S> {
type Response = S::Response;
type Error = S::Error;
type Future = S::Future;

#[inline]
fn call(&self, req: Request) -> Self::Future {
(**self).call(req)
}
}

impl<Request, S: Service<Request> + ?Sized> Service<Request> for std::rc::Rc<S> {
type Response = S::Response;
type Error = S::Error;
type Future = S::Future;

#[inline]
fn call(&self, req: Request) -> Self::Future {
(**self).call(req)
}
}

impl<Request, S: Service<Request> + ?Sized> Service<Request> for std::sync::Arc<S> {
type Response = S::Response;
type Error = S::Error;
type Future = S::Future;

#[inline]
fn call(&self, req: Request) -> Self::Future {
(**self).call(req)
}
}

0 comments on commit eade122

Please sign in to comment.