From 346858dcbb2e99d61ed8989f0c3045261d8d468b Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Thu, 12 Sep 2019 10:47:37 -0400 Subject: [PATCH 1/2] Remove Boxing Waiting on rust-lang/rust#63063. --- src/lib.rs | 1 + src/multiplex/client.rs | 10 +++++----- src/pipeline/client.rs | 10 +++++----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0b38dd0..5419325 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; diff --git a/src/multiplex/client.rs b/src/multiplex/client.rs index 045fb9c..c4c50ad 100644 --- a/src/multiplex/client.rs +++ b/src/multiplex/client.rs @@ -93,11 +93,11 @@ where { type Error = SpawnError; type Response = Client, Request>; - type Future = Pin> + Send>>; + type Future = impl Future> + Send; 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 +390,7 @@ where { type Response = T::Ok; type Error = E; - type Future = Pin> + Send>>; + type Future = impl Future> + Send; 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 +402,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 +413,7 @@ where }, Err(_) => Err(E::from(Error::TransportFull)), } - }) + } } } diff --git a/src/pipeline/client.rs b/src/pipeline/client.rs index fd61f87..05032e5 100644 --- a/src/pipeline/client.rs +++ b/src/pipeline/client.rs @@ -72,11 +72,11 @@ where { type Error = SpawnError; type Response = Client, Request>; - type Future = Pin> + Send>>; + type Future = impl Future> + Send; 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 +350,7 @@ where { type Response = T::Ok; type Error = E; - type Future = Pin> + Send>>; + type Future = impl Future> + Send; 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 +362,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 +373,7 @@ where }, Err(_) => Err(E::from(Error::TransportFull)), } - }) + } } } From 5ad387a93084b55e89c6af84f803d6802af93561 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Sat, 6 Jun 2020 10:22:48 -0400 Subject: [PATCH 2/2] Work around https://github.com/rust-lang/rust/issues/65863 --- src/error.rs | 2 +- src/lib.rs | 17 +++++++++++++++++ src/multiplex/client.rs | 8 ++++++++ src/multiplex/mod.rs | 2 +- src/pipeline/client.rs | 8 ++++++++ 5 files changed, 35 insertions(+), 2 deletions(-) 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 5419325..0228876 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -232,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 c4c50ad..e6043c7 100644 --- a/src/multiplex/client.rs +++ b/src/multiplex/client.rs @@ -93,7 +93,11 @@ where { type Error = SpawnError; type Response = Client, Request>; + + #[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); @@ -390,7 +394,11 @@ where { type Response = T::Ok; type Error = E; + + #[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))) 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 05032e5..f3b8544 100644 --- a/src/pipeline/client.rs +++ b/src/pipeline/client.rs @@ -72,7 +72,11 @@ where { type Error = SpawnError; type Response = Client, Request>; + + #[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); @@ -350,7 +354,11 @@ where { type Response = T::Ok; type Error = E; + + #[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)))