Skip to content

Commit 9b3f916

Browse files
committed
simplify code with futures_core
1 parent 7454509 commit 9b3f916

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ documentation = "https://docs.rs/async-io-converse/"
1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212

1313
[dependencies]
14+
futures-core = "0.3"
1415
futures-io = "0.3"
1516
futures-util = "0.3"
1617
async-io-typed = "1.0"

src/lib.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,9 @@ impl<R: AsyncRead + Unpin, W: AsyncWrite + Unpin, T: Serialize + DeserializeOwne
192192
ref raw_write,
193193
} = self.get_mut();
194194
loop {
195-
return match Pin::new(&mut *raw).poll_next(cx) {
196-
Poll::Ready(Some(Ok(i))) => {
195+
match futures_core::ready!(Pin::new(&mut *raw).poll_next(cx)) {
196+
Some(r) => {
197+
let i = r?;
197198
while let Ok(reply_data) = reply_data_receiver.try_recv() {
198199
pending_reply.push(reply_data);
199200
}
@@ -217,19 +218,17 @@ impl<R: AsyncRead + Unpin, W: AsyncWrite + Unpin, T: Serialize + DeserializeOwne
217218
!matches
218219
});
219220
if start_len == pending_reply.len() {
220-
Poll::Ready(Some(Ok(ReceivedMessage {
221+
return Poll::Ready(Some(Ok(ReceivedMessage {
221222
message: Some(user_message.take().expect("infallible")),
222223
conversation_id: i.conversation_id,
223224
raw_write: Arc::clone(raw_write),
224-
})))
225+
})));
225226
} else {
226227
continue;
227228
}
228-
}
229-
Poll::Ready(Some(Err(e))) => Poll::Ready(Some(Err(e.into()))),
230-
Poll::Ready(None) => Poll::Ready(None),
231-
Poll::Pending => Poll::Pending,
232-
};
229+
},
230+
None => return Poll::Ready(None),
231+
}
233232
}
234233
}
235234
}

0 commit comments

Comments
 (0)