use std::future::Future; use std::task::Context; use std::task::Poll; use tower::Service; pub trait MakeServiceRef: self::sealed::Sealed<(Target, Request)> { type Response; type Error; type Service: Service; type MakeError; type Future: Future>; fn poll_ready_ref(&mut self, cx: &mut Context) -> Poll>; fn make_service_ref(&mut self, target: &Target) -> Self::Future; } impl self::sealed::Sealed<(Target, Request)> for M where M: for<'a> Service<&'a Target, Response = S>, S: Service, { } impl MakeServiceRef for M where M: for<'a> Service<&'a Target, Response = S, Future = MF, Error = ME>, MF: Future>, S: Service, { type Response = S::Response; type Error = S::Error; type Service = S; type MakeError = ME; type Future = MF; fn poll_ready_ref(&mut self, cx: &mut Context) -> Poll> { self.poll_ready(cx) } fn make_service_ref(&mut self, target: &Target) -> Self::Future { self.call(target) } } mod sealed { pub trait Sealed {} }