mirror of
https://github.com/async-rs/async-std.git
synced 2025-01-31 17:55:35 +00:00
feat: Add StdinLock struct
This commit is contained in:
parent
94ef3dc2b2
commit
a5a00d7b14
1 changed files with 19 additions and 2 deletions
|
@ -47,6 +47,11 @@ pub fn stdin() -> Stdin {
|
|||
#[derive(Debug)]
|
||||
pub struct Stdin(Mutex<State>);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct StdinLock<'a>(std::io::StdinLock<'a>);
|
||||
|
||||
unsafe impl Send for StdinLock<'_> {}
|
||||
|
||||
/// The state of the asynchronous stdin.
|
||||
///
|
||||
/// The stdin can be either idle or busy performing an asynchronous operation.
|
||||
|
@ -157,12 +162,14 @@ impl Stdin {
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
pub async fn lock(&self) -> std::io::StdinLock<'static> {
|
||||
pub async fn lock(&self) -> StdinLock<'static> {
|
||||
lazy_static! {
|
||||
static ref STDIN: std::io::Stdin = std::io::stdin();
|
||||
}
|
||||
|
||||
STDIN.lock()
|
||||
blocking::spawn(async {
|
||||
StdinLock(STDIN.lock())
|
||||
}).await
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -248,3 +255,13 @@ cfg_if! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Read for StdinLock<'_> {
|
||||
fn poll_read(
|
||||
self: Pin<&mut Self>,
|
||||
_cx: &mut Context<'_>,
|
||||
_buf: &mut [u8],
|
||||
) -> Poll<io::Result<usize>> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue