Skip to content

Commit

Permalink
Work around rust-lang/rust#65863
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhoo committed Jun 6, 2020
1 parent 346858d commit 5ad387a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
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

0 comments on commit 5ad387a

Please sign in to comment.