tokio_fs/stderr.rs
1use tokio_io::AsyncWrite;
2
3use futures::Poll;
4
5use std::io::{self, Stderr as StdStderr, Write};
6
7/// A handle to the standard error stream of a process.
8///
9/// The handle implements the [`AsyncWrite`] trait, but beware that concurrent
10/// writes to `Stderr` must be executed with care.
11///
12/// Created by the [`stderr`] function.
13///
14/// [`stderr`]: fn.stderr.html
15/// [`AsyncWrite`]: trait.AsyncWrite.html
16#[derive(Debug)]
17pub struct Stderr {
18 std: StdStderr,
19}
20
21/// Constructs a new handle to the standard error of the current process.
22///
23/// The returned handle allows writing to standard error from the within the
24/// Tokio runtime.
25pub fn stderr() -> Stderr {
26 let std = io::stderr();
27 Stderr { std }
28}
29
30impl Write for Stderr {
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 Stderr {
41 fn shutdown(&mut self) -> Poll<(), io::Error> {
42 Ok(().into())
43 }
44}