File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ use lazy_static:: lazy_static;
1
2
use std:: pin:: Pin ;
2
3
use std:: sync:: Mutex ;
3
4
@@ -79,6 +80,35 @@ enum Operation {
79
80
Flush ( io:: Result < ( ) > ) ,
80
81
}
81
82
83
+ impl Stdout {
84
+ /// Locks this handle to the standard error stream, returning a writable guard.
85
+ ///
86
+ /// The lock is released when the returned lock goes out of scope. The returned guard also implements the Write trait for writing data.
87
+ ///
88
+ /// # Examples
89
+ ///
90
+ /// ```no_run
91
+ /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
92
+ /// #
93
+ /// use async_std::io;
94
+ /// use std::io::Write;
95
+ ///
96
+ /// let stdout = io::stdout();
97
+ /// let mut handle = stdout.lock().await;
98
+ ///
99
+ /// handle.write_all(b"hello world")?;
100
+ /// #
101
+ /// # Ok(()) }) }
102
+ /// ```
103
+ pub async fn lock ( & self ) -> std:: io:: StdoutLock < ' static > {
104
+ lazy_static ! {
105
+ static ref STDOUT : std:: io:: Stdout = std:: io:: stdout( ) ;
106
+ }
107
+
108
+ STDOUT . lock ( )
109
+ }
110
+ }
111
+
82
112
impl Write for Stdout {
83
113
fn poll_write (
84
114
mut self : Pin < & mut Self > ,
You can’t perform that action at this time.
0 commit comments