Skip to content

Commit eade122

Browse files
authoredMay 27, 2024··
feat(service): implement Service for reference types (#3607)
1 parent 3b858ed commit eade122

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
 

‎src/service/service.rs

+55
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,58 @@ pub trait Service<Request> {
3838
/// The discussion on this is here: <https://github.com/hyperium/hyper/issues/3040>
3939
fn call(&self, req: Request) -> Self::Future;
4040
}
41+
42+
impl<Request, S: Service<Request> + ?Sized> Service<Request> for &'_ S {
43+
type Response = S::Response;
44+
type Error = S::Error;
45+
type Future = S::Future;
46+
47+
#[inline]
48+
fn call(&self, req: Request) -> Self::Future {
49+
(**self).call(req)
50+
}
51+
}
52+
53+
impl<Request, S: Service<Request> + ?Sized> Service<Request> for &'_ mut S {
54+
type Response = S::Response;
55+
type Error = S::Error;
56+
type Future = S::Future;
57+
58+
#[inline]
59+
fn call(&self, req: Request) -> Self::Future {
60+
(**self).call(req)
61+
}
62+
}
63+
64+
impl<Request, S: Service<Request> + ?Sized> Service<Request> for Box<S> {
65+
type Response = S::Response;
66+
type Error = S::Error;
67+
type Future = S::Future;
68+
69+
#[inline]
70+
fn call(&self, req: Request) -> Self::Future {
71+
(**self).call(req)
72+
}
73+
}
74+
75+
impl<Request, S: Service<Request> + ?Sized> Service<Request> for std::rc::Rc<S> {
76+
type Response = S::Response;
77+
type Error = S::Error;
78+
type Future = S::Future;
79+
80+
#[inline]
81+
fn call(&self, req: Request) -> Self::Future {
82+
(**self).call(req)
83+
}
84+
}
85+
86+
impl<Request, S: Service<Request> + ?Sized> Service<Request> for std::sync::Arc<S> {
87+
type Response = S::Response;
88+
type Error = S::Error;
89+
type Future = S::Future;
90+
91+
#[inline]
92+
fn call(&self, req: Request) -> Self::Future {
93+
(**self).call(req)
94+
}
95+
}

0 commit comments

Comments
 (0)
Please sign in to comment.