chore(client): place the use of new rust features behind cfg

This commit is contained in:
Niv Kaminer
2018-08-04 10:21:57 +03:00
committed by Sean McArthur
parent 97f4243a59
commit 9f8add6056
5 changed files with 83 additions and 1 deletions

View File

@@ -238,6 +238,7 @@ where
}
}
#[cfg(impl_trait_available)]
pub(crate) fn send_request_retryable(&mut self, req: Request<B>) -> impl Future<Item = Response<Body>, Error = (::Error, Option<Request<B>>)> + Send
where
B: Send,
@@ -260,6 +261,31 @@ where
}
}
}
#[cfg(not(impl_trait_available))]
pub(super) fn send_request_retryable(&mut self, req: Request<B>) -> Box<Future<Item=Response<Body>, Error=(::Error, Option<Request<B>>)> + Send>
where
B: Send,
{
let inner = match self.dispatch.try_send(req) {
Ok(rx) => {
Either::A(rx.then(move |res| {
match res {
Ok(Ok(res)) => Ok(res),
Ok(Err(err)) => Err(err),
// this is definite bug if it happens, but it shouldn't happen!
Err(_) => panic!("dispatch dropped without returning error"),
}
}))
},
Err(req) => {
debug!("connection was not ready");
let err = ::Error::new_canceled(Some("connection was not ready"));
Either::B(future::err((err, Some(req))))
}
};
Box::new(inner)
}
}
/* TODO(0.12.0): when we change from tokio-service to tower.
@@ -298,6 +324,7 @@ impl<B> Http2SendRequest<B>
where
B: Payload + 'static,
{
#[cfg(impl_trait_available)]
pub(super) fn send_request_retryable(&mut self, req: Request<B>) -> impl Future<Item=Response<Body>, Error=(::Error, Option<Request<B>>)> + Send
where
B: Send,
@@ -320,6 +347,31 @@ where
}
}
}
#[cfg(not(impl_trait_available))]
pub(crate) fn send_request_retryable(&mut self, req: Request<B>) -> Box<Future<Item=Response<Body>, Error=(::Error, Option<Request<B>>)> + Send>
where
B: Send,
{
let inner = match self.dispatch.try_send(req) {
Ok(rx) => {
Either::A(rx.then(move |res| {
match res {
Ok(Ok(res)) => Ok(res),
Ok(Err(err)) => Err(err),
// this is definite bug if it happens, but it shouldn't happen!
Err(_) => panic!("dispatch dropped without returning error"),
}
}))
},
Err(req) => {
debug!("connection was not ready");
let err = ::Error::new_canceled(Some("connection was not ready"));
Either::B(future::err((err, Some(req))))
}
};
Box::new(inner)
}
}
impl<B> fmt::Debug for Http2SendRequest<B> {

View File

@@ -623,6 +623,7 @@ impl<B> PoolClient<B> {
}
impl<B: Payload + 'static> PoolClient<B> {
#[cfg(impl_trait_available)]
fn send_request_retryable(&mut self, req: Request<B>) -> impl Future<Item = Response<Body>, Error = (::Error, Option<Request<B>>)> + Send
where
B: Send,
@@ -632,6 +633,17 @@ impl<B: Payload + 'static> PoolClient<B> {
PoolTx::Http2(ref mut tx) => Either::B(tx.send_request_retryable(req)),
}
}
#[cfg(not(impl_trait_available))]
fn send_request_retryable(&mut self, req: Request<B>) -> Box<Future<Item=Response<Body>, Error=(::Error, Option<Request<B>>)> + Send>
where
B: Send,
{
match self.tx {
PoolTx::Http1(ref mut tx) => tx.send_request_retryable(req),
PoolTx::Http2(ref mut tx) => tx.send_request_retryable(req),
}
}
}
impl<B> Poolable for PoolClient<B>