Skip to content

Commit 1be426e

Browse files
committed
feat: Add stdin.lock method prototype
1 parent da9cbd9 commit 1be426e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/io/stdin.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use lazy_static::lazy_static;
12
use std::pin::Pin;
23
use std::sync::Mutex;
34

@@ -7,6 +8,10 @@ use crate::future::{self, Future};
78
use crate::io::{self, Read};
89
use crate::task::{blocking, Context, Poll};
910

11+
lazy_static! {
12+
static ref STDIN: std::io::Stdin = std::io::stdin();
13+
}
14+
1015
/// Constructs a new handle to the standard input of the current process.
1116
///
1217
/// This function is an async version of [`std::io::stdin`].
@@ -134,6 +139,29 @@ impl Stdin {
134139
})
135140
.await
136141
}
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+
}
137165
}
138166

139167
impl Read for Stdin {

0 commit comments

Comments
 (0)