mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-28 00:00:11 +02:00
fs: use async fn instead of custom futures (#1381)
Also update all the doc examples.
This commit is contained in:
+6
-13
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user