fs: use async fn instead of custom futures (#1381)

Also update all the doc examples.
This commit is contained in:
Carl Lerche
2019-08-04 11:24:30 -07:00
committed by GitHub
parent 337646b97f
commit 6cbe3d4f82
36 changed files with 691 additions and 1668 deletions
+6 -13
View File
@@ -1,6 +1,8 @@
use crate::blocking_io;
use tokio_io::AsyncRead;
use std::io::{self, Read, Stdin as StdStdin};
use std::io::{self, Read};
use std::pin::Pin;
use std::task::Context;
use std::task::Poll;
@@ -22,7 +24,7 @@ use std::task::Poll;
/// [`AsyncRead`]: trait.AsyncRead.html
#[derive(Debug)]
pub struct Stdin {
std: StdStdin,
std: std::io::Stdin,
}
/// Constructs a new handle to the standard input of the current process.
@@ -34,21 +36,12 @@ pub fn stdin() -> Stdin {
Stdin { std }
}
impl Read for Stdin {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
crate::would_block(|| self.std.read(buf))
}
}
impl AsyncRead for Stdin {
fn poll_read(
self: Pin<&mut Self>,
mut self: Pin<&mut Self>,
_cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<io::Result<usize>> {
match Pin::get_mut(self).read(buf) {
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => Poll::Pending,
other => Poll::Ready(other),
}
blocking_io(|| (&mut self.std).read(buf))
}
}