From eade122db25f51619aee5db845de2a61b7ff2f74 Mon Sep 17 00:00:00 2001 From: Liam Perlaki Date: Mon, 27 May 2024 14:58:06 +0200 Subject: [PATCH] feat(service): implement Service for reference types (#3607) --- src/service/service.rs | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/service/service.rs b/src/service/service.rs index c6db129bf4..1b9aea5162 100644 --- a/src/service/service.rs +++ b/src/service/service.rs @@ -38,3 +38,58 @@ pub trait Service { /// The discussion on this is here: fn call(&self, req: Request) -> Self::Future; } + +impl + ?Sized> Service 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 + ?Sized> Service 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 + ?Sized> Service for Box { + type Response = S::Response; + type Error = S::Error; + type Future = S::Future; + + #[inline] + fn call(&self, req: Request) -> Self::Future { + (**self).call(req) + } +} + +impl + ?Sized> Service for std::rc::Rc { + type Response = S::Response; + type Error = S::Error; + type Future = S::Future; + + #[inline] + fn call(&self, req: Request) -> Self::Future { + (**self).call(req) + } +} + +impl + ?Sized> Service for std::sync::Arc { + type Response = S::Response; + type Error = S::Error; + type Future = S::Future; + + #[inline] + fn call(&self, req: Request) -> Self::Future { + (**self).call(req) + } +}