File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-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
@@ -7,6 +8,10 @@ use crate::future::{self, Future};
7
8
use crate :: io:: { self , Read } ;
8
9
use crate :: task:: { blocking, Context , Poll } ;
9
10
11
+ lazy_static ! {
12
+ static ref STDIN : std:: io:: Stdin = std:: io:: stdin( ) ;
13
+ }
14
+
10
15
/// Constructs a new handle to the standard input of the current process.
11
16
///
12
17
/// This function is an async version of [`std::io::stdin`].
@@ -134,6 +139,29 @@ impl Stdin {
134
139
} )
135
140
. await
136
141
}
142
+
143
+ /// Reads a line of input into the specified buffer.
144
+ ///
145
+ /// # Examples
146
+ ///
147
+ /// ```no_run
148
+ /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
149
+ /// #
150
+ /// use async_std::io;
151
+ /// use std::io::Read;
152
+ ///
153
+ /// let mut buffer = String::new();
154
+ ///
155
+ /// let stdin = io::stdin();
156
+ /// let mut handle = stdin.lock().await;
157
+ ///
158
+ /// handle.read_to_string(&mut buffer)?;
159
+ /// #
160
+ /// # Ok(()) }) }
161
+ /// ```
162
+ pub async fn lock ( & self ) -> std:: io:: StdinLock < ' static > {
163
+ STDIN . lock ( )
164
+ }
137
165
}
138
166
139
167
impl Read for Stdin {
You can’t perform that action at this time.
0 commit comments