Skip to content
This repository was archived by the owner on Oct 30, 2019. It is now read-only.

Commit 4f2e6f0

Browse files
taiki-eyoshuawuyts
authored andcommitted
Use ? operator more (#33)
1 parent 2e41ca0 commit 4f2e6f0

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

runtime-tokio/src/tcp.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,17 @@ pub(crate) struct TcpListener {
2020

2121
impl runtime_raw::TcpStream for TcpStream {
2222
fn poll_write_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
23-
match self.tokio_stream.poll_write_ready() {
24-
Err(e) => Poll::Ready(Err(e)),
25-
Ok(futures01::Async::Ready(_)) => Poll::Ready(Ok(())),
26-
Ok(futures01::Async::NotReady) => Poll::Pending,
23+
match self.tokio_stream.poll_write_ready()? {
24+
futures01::Async::Ready(_) => Poll::Ready(Ok(())),
25+
futures01::Async::NotReady => Poll::Pending,
2726
}
2827
}
2928

3029
fn poll_read_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
3130
let mask = mio::Ready::readable();
32-
match self.tokio_stream.poll_read_ready(mask) {
33-
Err(e) => Poll::Ready(Err(e)),
34-
Ok(futures01::Async::Ready(_)) => Poll::Ready(Ok(())),
35-
Ok(futures01::Async::NotReady) => Poll::Pending,
31+
match self.tokio_stream.poll_read_ready(mask)? {
32+
futures01::Async::Ready(_) => Poll::Ready(Ok(())),
33+
futures01::Async::NotReady => Poll::Pending,
3634
}
3735
}
3836

@@ -101,13 +99,12 @@ impl runtime_raw::TcpListener for TcpListener {
10199
_cx: &mut Context<'_>,
102100
) -> Poll<io::Result<Pin<Box<dyn runtime_raw::TcpStream>>>> {
103101
let listener = unsafe { &mut self.get_unchecked_mut().tokio_listener };
104-
match listener.poll_accept() {
105-
Err(e) => Poll::Ready(Err(e)),
106-
Ok(futures01::Async::Ready((tokio_stream, _))) => {
102+
match listener.poll_accept()? {
103+
futures01::Async::Ready((tokio_stream, _)) => {
107104
let stream = Box::pin(TcpStream { tokio_stream });
108105
Poll::Ready(Ok(stream))
109106
}
110-
Ok(futures01::Async::NotReady) => Poll::Pending,
107+
futures01::Async::NotReady => Poll::Pending,
111108
}
112109
}
113110

runtime-tokio/src/udp.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ impl runtime_raw::UdpSocket for UdpSocket {
2222
receiver: &SocketAddr,
2323
) -> Poll<io::Result<usize>> {
2424
let socket = unsafe { &mut self.get_unchecked_mut().tokio_socket };
25-
match socket.poll_send_to(&buf, &receiver) {
26-
Err(e) => Poll::Ready(Err(e)),
27-
Ok(futures01::Async::Ready(size)) => Poll::Ready(Ok(size)),
28-
Ok(futures01::Async::NotReady) => Poll::Pending,
25+
match socket.poll_send_to(&buf, &receiver)? {
26+
futures01::Async::Ready(size) => Poll::Ready(Ok(size)),
27+
futures01::Async::NotReady => Poll::Pending,
2928
}
3029
}
3130

@@ -35,10 +34,9 @@ impl runtime_raw::UdpSocket for UdpSocket {
3534
buf: &mut [u8],
3635
) -> Poll<io::Result<(usize, SocketAddr)>> {
3736
let socket = unsafe { &mut self.get_unchecked_mut().tokio_socket };
38-
match socket.poll_recv_from(buf) {
39-
Err(e) => Poll::Ready(Err(e)),
40-
Ok(futures01::Async::Ready((size, addr))) => Poll::Ready(Ok((size, addr))),
41-
Ok(futures01::Async::NotReady) => Poll::Pending,
37+
match socket.poll_recv_from(buf)? {
38+
futures01::Async::Ready((size, addr)) => Poll::Ready(Ok((size, addr))),
39+
futures01::Async::NotReady => Poll::Pending,
4240
}
4341
}
4442

src/net/tcp.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,9 @@ impl<'stream> Future for Accept<'stream> {
463463
type Output = io::Result<(TcpStream, SocketAddr)>;
464464

465465
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
466-
match ready!(self.inner.poll_next_unpin(cx)).unwrap() {
467-
Err(err) => Poll::Ready(Err(err)),
468-
Ok(stream) => {
469-
let addr = stream.peer_addr().unwrap();
470-
Poll::Ready(Ok((stream, addr)))
471-
}
472-
}
466+
let stream = ready!(self.inner.poll_next_unpin(cx)).unwrap()?;
467+
let addr = stream.peer_addr().unwrap();
468+
Poll::Ready(Ok((stream, addr)))
473469
}
474470
}
475471

0 commit comments

Comments
 (0)