mirror of
https://github.com/async-rs/async-std.git
synced 2025-04-01 22:16:40 +00:00
feat: Add StderrLock and StdoutLock struct
This commit is contained in:
parent
48b255897e
commit
59615a655b
3 changed files with 51 additions and 5 deletions
|
@ -44,6 +44,11 @@ pub fn stderr() -> Stderr {
|
|||
#[derive(Debug)]
|
||||
pub struct Stderr(Mutex<State>);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct StderrLock<'a>(std::io::StderrLock<'a>);
|
||||
|
||||
unsafe impl Send for StderrLock<'_> {}
|
||||
|
||||
/// The state of the asynchronous stderr.
|
||||
///
|
||||
/// The stderr can be either idle or busy performing an asynchronous operation.
|
||||
|
@ -98,12 +103,12 @@ impl Stderr {
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
pub async fn lock(&self) -> std::io::StderrLock<'static> {
|
||||
pub async fn lock(&self) -> StderrLock<'static> {
|
||||
lazy_static! {
|
||||
static ref STDERR: std::io::Stderr = std::io::stderr();
|
||||
}
|
||||
|
||||
STDERR.lock()
|
||||
blocking::spawn(move || StderrLock(STDERR.lock())).await
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -209,3 +214,21 @@ cfg_windows! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Write for StderrLock<'_> {
|
||||
fn poll_write(
|
||||
self: Pin<&mut Self>,
|
||||
_cx: &mut Context<'_>,
|
||||
_buf: &[u8],
|
||||
) -> Poll<io::Result<usize>> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn poll_close(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -165,7 +165,7 @@ impl Stdin {
|
|||
static ref STDIN: std::io::Stdin = std::io::stdin();
|
||||
}
|
||||
|
||||
blocking::spawn(move || { StdinLock(STDIN.lock()) }).await
|
||||
blocking::spawn(move || StdinLock(STDIN.lock())).await
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,11 @@ pub fn stdout() -> Stdout {
|
|||
#[derive(Debug)]
|
||||
pub struct Stdout(Mutex<State>);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct StdoutLock<'a>(std::io::StdoutLock<'a>);
|
||||
|
||||
unsafe impl Send for StdoutLock<'_> {}
|
||||
|
||||
/// The state of the asynchronous stdout.
|
||||
///
|
||||
/// The stdout can be either idle or busy performing an asynchronous operation.
|
||||
|
@ -98,12 +103,12 @@ impl Stdout {
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
pub async fn lock(&self) -> std::io::StdoutLock<'static> {
|
||||
pub async fn lock(&self) -> StdoutLock<'static> {
|
||||
lazy_static! {
|
||||
static ref STDOUT: std::io::Stdout = std::io::stdout();
|
||||
}
|
||||
|
||||
STDOUT.lock()
|
||||
blocking::spawn(move || StdoutLock(STDOUT.lock())).await
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -209,3 +214,21 @@ cfg_windows! {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Write for StdoutLock<'_> {
|
||||
fn poll_write(
|
||||
self: Pin<&mut Self>,
|
||||
_cx: &mut Context<'_>,
|
||||
_buf: &[u8],
|
||||
) -> Poll<io::Result<usize>> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn poll_close(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue