|
1 | 1 | use lazy_static::lazy_static; |
| 2 | +use std::io::Write as StdWrite; |
2 | 3 | use std::pin::Pin; |
3 | 4 | use std::sync::Mutex; |
4 | 5 |
|
@@ -54,6 +55,11 @@ pub fn stderr() -> Stderr { |
54 | 55 | #[derive(Debug)] |
55 | 56 | pub struct Stderr(Mutex<State>); |
56 | 57 |
|
| 58 | +/// A locked reference to the Stderr handle. |
| 59 | +/// This handle implements the [`Write`] traits, and is constructed via the [`Stderr::lock`] method. |
| 60 | +/// |
| 61 | +/// [`Write`]: trait.Read.html |
| 62 | +/// [`Stderr::lock`]: struct.Stderr.html#method.lock |
57 | 63 | #[derive(Debug)] |
58 | 64 | pub struct StderrLock<'a>(std::io::StderrLock<'a>); |
59 | 65 |
|
@@ -104,12 +110,12 @@ impl Stderr { |
104 | 110 | /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { |
105 | 111 | /// # |
106 | 112 | /// use async_std::io; |
107 | | - /// use std::io::Write; |
| 113 | + /// use async_std::prelude::*; |
108 | 114 | /// |
109 | 115 | /// let stderr = io::stderr(); |
110 | 116 | /// let mut handle = stderr.lock().await; |
111 | 117 | /// |
112 | | - /// handle.write_all(b"hello world")?; |
| 118 | + /// handle.write_all(b"hello world").await?; |
113 | 119 | /// # |
114 | 120 | /// # Ok(()) }) } |
115 | 121 | /// ``` |
@@ -227,18 +233,18 @@ cfg_windows! { |
227 | 233 |
|
228 | 234 | impl Write for StderrLock<'_> { |
229 | 235 | fn poll_write( |
230 | | - self: Pin<&mut Self>, |
| 236 | + mut self: Pin<&mut Self>, |
231 | 237 | _cx: &mut Context<'_>, |
232 | | - _buf: &[u8], |
| 238 | + buf: &[u8], |
233 | 239 | ) -> Poll<io::Result<usize>> { |
234 | | - unimplemented!() |
| 240 | + Poll::Ready(self.0.write(buf)) |
235 | 241 | } |
236 | 242 |
|
237 | | - fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> { |
238 | | - unimplemented!() |
| 243 | + fn poll_flush(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> { |
| 244 | + Poll::Ready(self.0.flush()) |
239 | 245 | } |
240 | 246 |
|
241 | | - fn poll_close(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> { |
242 | | - unimplemented!() |
| 247 | + fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> { |
| 248 | + self.poll_flush(cx) |
243 | 249 | } |
244 | 250 | } |
0 commit comments