diff --git a/src/error.rs b/src/error.rs index f9c5824..41ffff7 100644 --- a/src/error.rs +++ b/src/error.rs @@ -17,7 +17,7 @@ where /// Attempted to issue a `call` when no more requests can be in flight. /// - /// See [`tower_service::Service::poll_ready`] and [`Client::with_limit`]. + /// See [`tower_service::Service::poll_ready`]. TransportFull, /// Attempted to issue a `call`, but the underlying transport has been closed. diff --git a/src/lib.rs b/src/lib.rs index 0b38dd0..0228876 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -140,6 +140,7 @@ rust_2018_idioms )] #![allow(clippy::type_complexity)] +#![feature(type_alias_impl_trait)] const YIELD_EVERY: usize = 24; @@ -231,3 +232,20 @@ mod sealed { pub mod multiplex; pub mod pipeline; + +/// impl Future. +/// +/// https://github.com/rust-lang/rust/issues/65863 +#[cfg(doc)] +pub struct DocFuture(std::marker::PhantomData); + +#[cfg(doc)] +impl std::future::Future for DocFuture { + type Output = O; + fn poll( + self: std::pin::Pin<&mut Self>, + _: &mut std::task::Context<'_>, + ) -> std::task::Poll { + unreachable!() + } +} diff --git a/src/multiplex/client.rs b/src/multiplex/client.rs index 045fb9c..e6043c7 100644 --- a/src/multiplex/client.rs +++ b/src/multiplex/client.rs @@ -93,11 +93,15 @@ where { type Error = SpawnError; type Response = Client, Request>; - type Future = Pin> + Send>>; + + #[cfg(not(doc))] + type Future = impl Future> + Send; + #[cfg(doc)] + type Future = crate::DocFuture>; fn call(&mut self, target: Target) -> Self::Future { let maker = self.t_maker.make_transport(target); - Box::pin(async move { Ok(Client::new(maker.await.map_err(SpawnError::Inner)?)) }) + async move { Ok(Client::new(maker.await.map_err(SpawnError::Inner)?)) } } fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { @@ -390,7 +394,11 @@ where { type Response = T::Ok; type Error = E; - type Future = Pin> + Send>>; + + #[cfg(not(doc))] + type Future = impl Future> + Send; + #[cfg(doc)] + type Future = crate::DocFuture>; fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { Poll::Ready(ready!(self.mediator.poll_ready(cx)).map_err(|_| E::from(Error::ClientDropped))) @@ -402,7 +410,7 @@ where tracing::trace!("issuing request"); let req = ClientRequest { req, span, res: tx }; let r = self.mediator.try_send(req); - Box::pin(async move { + async move { match r { Ok(()) => match rx.await { Ok(r) => { @@ -413,7 +421,7 @@ where }, Err(_) => Err(E::from(Error::TransportFull)), } - }) + } } } diff --git a/src/multiplex/mod.rs b/src/multiplex/mod.rs index f63cb1b..4aa780b 100644 --- a/src/multiplex/mod.rs +++ b/src/multiplex/mod.rs @@ -26,7 +26,7 @@ pub mod server; pub use self::server::Server; /// A convenience wrapper that lets you take separate transport and tag store types and use them as -/// a single [`client::Transport`]. +/// a single transport. #[pin_project] #[derive(Debug)] pub struct MultiplexTransport { diff --git a/src/pipeline/client.rs b/src/pipeline/client.rs index fd61f87..f3b8544 100644 --- a/src/pipeline/client.rs +++ b/src/pipeline/client.rs @@ -72,11 +72,15 @@ where { type Error = SpawnError; type Response = Client, Request>; - type Future = Pin> + Send>>; + + #[cfg(not(doc))] + type Future = impl Future> + Send; + #[cfg(doc)] + type Future = crate::DocFuture>; fn call(&mut self, target: Target) -> Self::Future { let maker = self.t_maker.make_transport(target); - Box::pin(async move { Ok(Client::new(maker.await.map_err(SpawnError::Inner)?)) }) + async move { Ok(Client::new(maker.await.map_err(SpawnError::Inner)?)) } } fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { @@ -350,7 +354,11 @@ where { type Response = T::Ok; type Error = E; - type Future = Pin> + Send>>; + + #[cfg(not(doc))] + type Future = impl Future> + Send; + #[cfg(doc)] + type Future = crate::DocFuture>; fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { Poll::Ready(ready!(self.mediator.poll_ready(cx)).map_err(|_| E::from(Error::ClientDropped))) @@ -362,7 +370,7 @@ where tracing::trace!("issuing request"); let req = ClientRequest { req, span, res: tx }; let r = self.mediator.try_send(req); - Box::pin(async move { + async move { match r { Ok(()) => match rx.await { Ok(r) => { @@ -373,7 +381,7 @@ where }, Err(_) => Err(E::from(Error::TransportFull)), } - }) + } } }