feat: Add StderrLock and StdoutLock struct

pull/334/head
k-nasa 5 years ago
parent 48b255897e
commit 59615a655b

@ -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…
Cancel
Save