feat: Add Stderr::lock

poc-serde-support
k-nasa 5 years ago
parent c7f6543502
commit f9741e7488

@ -1,3 +1,4 @@
use lazy_static::lazy_static;
use std::pin::Pin;
use std::sync::Mutex;
@ -79,6 +80,35 @@ enum Operation {
Flush(io::Result<()>),
}
impl Stderr {
/// Locks this handle to the standard error stream, returning a writable guard.
///
/// The lock is released when the returned lock goes out of scope. The returned guard also implements the Write trait for writing data.
///
/// # Examples
///
/// ```no_run
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::io;
/// use std::io::Write;
///
/// let stderr = io::stderr();
/// let mut handle = stderr.lock().await;
///
/// handle.write_all(b"hello world")?;
/// #
/// # Ok(()) }) }
/// ```
pub async fn lock(&self) -> std::io::StderrLock<'static> {
lazy_static! {
static ref STDERR: std::io::Stderr = std::io::stderr();
}
STDERR.lock()
}
}
impl Write for Stderr {
fn poll_write(
mut self: Pin<&mut Self>,

Loading…
Cancel
Save