Skip to content

Commit 21226a5

Browse files
authored
style(client): use std::task::ready! macro to simplify Poll branch matching (#2781)
1 parent 82086e7 commit 21226a5

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/async_impl/client.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::future::Future;
66
use std::net::IpAddr;
77
use std::pin::Pin;
88
use std::sync::Arc;
9-
use std::task::{Context, Poll};
9+
use std::task::{ready, Context, Poll};
1010
use std::time::Duration;
1111
use std::{collections::HashMap, convert::TryInto, net::SocketAddr};
1212
use std::{fmt, str};
@@ -3009,8 +3009,8 @@ impl Future for PendingRequest {
30093009

30103010
loop {
30113011
let res = match self.as_mut().in_flight().get_mut() {
3012-
ResponseFuture::Default(r) => match Pin::new(r).poll(cx) {
3013-
Poll::Ready(Err(e)) => {
3012+
ResponseFuture::Default(r) => match ready!(Pin::new(r).poll(cx)) {
3013+
Err(e) => {
30143014
#[cfg(feature = "http2")]
30153015
if e.is_request() {
30163016
if let Some(e) = e.source() {
@@ -3022,21 +3022,19 @@ impl Future for PendingRequest {
30223022

30233023
return Poll::Ready(Err(e.if_no_url(|| self.url.clone())));
30243024
}
3025-
Poll::Ready(Ok(res)) => res.map(super::body::boxed),
3026-
Poll::Pending => return Poll::Pending,
3025+
Ok(res) => res.map(super::body::boxed),
30273026
},
30283027
#[cfg(feature = "http3")]
3029-
ResponseFuture::H3(r) => match Pin::new(r).poll(cx) {
3030-
Poll::Ready(Err(e)) => {
3028+
ResponseFuture::H3(r) => match ready!(Pin::new(r).poll(cx)) {
3029+
Err(e) => {
30313030
if self.as_mut().retry_error(&e) {
30323031
continue;
30333032
}
30343033
return Poll::Ready(Err(
30353034
crate::error::request(e).with_url(self.url.clone())
30363035
));
30373036
}
3038-
Poll::Ready(Ok(res)) => res,
3039-
Poll::Pending => return Poll::Pending,
3037+
Ok(res) => res,
30403038
},
30413039
};
30423040

0 commit comments

Comments
 (0)