Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

forward implement Service for reference types #3607

Merged
merged 2 commits into from May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/service/service.rs
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)
}
}