Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Boxing of response futures #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Work around rust-lang/rust#65863
  • Loading branch information
jonhoo committed Jun 6, 2020
commit 5ad387a93084b55e89c6af84f803d6802af93561
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<O>(std::marker::PhantomData<O>);

#[cfg(doc)]
impl<O> std::future::Future for DocFuture<O> {
type Output = O;
fn poll(
self: std::pin::Pin<&mut Self>,
_: &mut std::task::Context<'_>,
) -> std::task::Poll<Self::Output> {
unreachable!()
}
}
8 changes: 8 additions & 0 deletions src/multiplex/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ where
{
type Error = SpawnError<NT::MakeError>;
type Response = Client<NT::Transport, Error<NT::Transport, Request>, Request>;

#[cfg(not(doc))]
type Future = impl Future<Output = Result<Self::Response, Self::Error>> + Send;
#[cfg(doc)]
type Future = crate::DocFuture<Result<Self::Response, Self::Error>>;

fn call(&mut self, target: Target) -> Self::Future {
let maker = self.t_maker.make_transport(target);
Expand Down Expand Up @@ -390,7 +394,11 @@ where
{
type Response = T::Ok;
type Error = E;

#[cfg(not(doc))]
type Future = impl Future<Output = Result<Self::Response, Self::Error>> + Send;
#[cfg(doc)]
type Future = crate::DocFuture<Result<Self::Response, Self::Error>>;

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), E>> {
Poll::Ready(ready!(self.mediator.poll_ready(cx)).map_err(|_| E::from(Error::ClientDropped)))
Expand Down
2 changes: 1 addition & 1 deletion src/multiplex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, S> {
Expand Down
8 changes: 8 additions & 0 deletions src/pipeline/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ where
{
type Error = SpawnError<NT::MakeError>;
type Response = Client<NT::Transport, Error<NT::Transport, Request>, Request>;

#[cfg(not(doc))]
type Future = impl Future<Output = Result<Self::Response, Self::Error>> + Send;
#[cfg(doc)]
type Future = crate::DocFuture<Result<Self::Response, Self::Error>>;

fn call(&mut self, target: Target) -> Self::Future {
let maker = self.t_maker.make_transport(target);
Expand Down Expand Up @@ -350,7 +354,11 @@ where
{
type Response = T::Ok;
type Error = E;

#[cfg(not(doc))]
type Future = impl Future<Output = Result<Self::Response, Self::Error>> + Send;
#[cfg(doc)]
type Future = crate::DocFuture<Result<Self::Response, Self::Error>>;

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), E>> {
Poll::Ready(ready!(self.mediator.poll_ready(cx)).map_err(|_| E::from(Error::ClientDropped)))
Expand Down