Skip to content

Commit a5a00d7

Browse files
committed
feat: Add StdinLock struct
1 parent 94ef3dc commit a5a00d7

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/io/stdin.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ pub fn stdin() -> Stdin {
4747
#[derive(Debug)]
4848
pub struct Stdin(Mutex<State>);
4949

50+
#[derive(Debug)]
51+
pub struct StdinLock<'a>(std::io::StdinLock<'a>);
52+
53+
unsafe impl Send for StdinLock<'_> {}
54+
5055
/// The state of the asynchronous stdin.
5156
///
5257
/// The stdin can be either idle or busy performing an asynchronous operation.
@@ -157,12 +162,14 @@ impl Stdin {
157162
/// #
158163
/// # Ok(()) }) }
159164
/// ```
160-
pub async fn lock(&self) -> std::io::StdinLock<'static> {
165+
pub async fn lock(&self) -> StdinLock<'static> {
161166
lazy_static! {
162167
static ref STDIN: std::io::Stdin = std::io::stdin();
163168
}
164169

165-
STDIN.lock()
170+
blocking::spawn(async {
171+
StdinLock(STDIN.lock())
172+
}).await
166173
}
167174
}
168175

@@ -248,3 +255,13 @@ cfg_if! {
248255
}
249256
}
250257
}
258+
259+
impl Read for StdinLock<'_> {
260+
fn poll_read(
261+
self: Pin<&mut Self>,
262+
_cx: &mut Context<'_>,
263+
_buf: &mut [u8],
264+
) -> Poll<io::Result<usize>> {
265+
unimplemented!()
266+
}
267+
}

0 commit comments

Comments
 (0)