tokio_fs/
stdout.rs

1use tokio_io::AsyncWrite;
2
3use futures::Poll;
4
5use std::io::{self, Stdout as StdStdout, Write};
6
7/// A handle to the standard output stream of a process.
8///
9/// The handle implements the [`AsyncWrite`] trait, but beware that concurrent
10/// writes to `Stdout` must be executed with care.
11///
12/// Created by the [`stdout`] function.
13///
14/// [`stdout`]: fn.stdout.html
15/// [`AsyncWrite`]: trait.AsyncWrite.html
16#[derive(Debug)]
17pub struct Stdout {
18    std: StdStdout,
19}
20
21/// Constructs a new handle to the standard output of the current process.
22///
23/// The returned handle allows writing to standard out from the within the Tokio
24/// runtime.
25pub fn stdout() -> Stdout {
26    let std = io::stdout();
27    Stdout { std }
28}
29
30impl Write for Stdout {
31    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
32        ::would_block(|| self.std.write(buf))
33    }
34
35    fn flush(&mut self) -> io::Result<()> {
36        ::would_block(|| self.std.flush())
37    }
38}
39
40impl AsyncWrite for Stdout {
41    fn shutdown(&mut self) -> Poll<(), io::Error> {
42        Ok(().into())
43    }
44}