forked from mirror/async-std
feat: Stabilize io::Std*Lock
This commit is contained in:
parent
9167d42f4b
commit
23b7c174f3
4 changed files with 9 additions and 45 deletions
|
@ -309,9 +309,9 @@ cfg_default! {
|
|||
#[doc(hidden)]
|
||||
pub use stdio::{_eprint, _print};
|
||||
|
||||
pub use stderr::{stderr, Stderr};
|
||||
pub use stdin::{stdin, Stdin};
|
||||
pub use stdout::{stdout, Stdout};
|
||||
pub use stderr::{stderr, Stderr, StderrLock};
|
||||
pub use stdin::{stdin, Stdin, StdinLock};
|
||||
pub use stdout::{stdout, Stdout, StdoutLock};
|
||||
pub use timeout::timeout;
|
||||
|
||||
mod timeout;
|
||||
|
@ -320,9 +320,3 @@ cfg_default! {
|
|||
mod stdio;
|
||||
mod stdout;
|
||||
}
|
||||
|
||||
cfg_unstable_default! {
|
||||
pub use stderr::StderrLock;
|
||||
pub use stdin::StdinLock;
|
||||
pub use stdout::StdoutLock;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
use std::pin::Pin;
|
||||
use std::sync::Mutex;
|
||||
use std::future::Future;
|
||||
use std::io::Write as _;
|
||||
|
||||
use crate::io::{self, Write};
|
||||
use crate::task::{spawn_blocking, Context, JoinHandle, Poll};
|
||||
|
||||
cfg_unstable! {
|
||||
use once_cell::sync::Lazy;
|
||||
use std::io::Write as _;
|
||||
}
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
/// Constructs a new handle to the standard error of the current process.
|
||||
///
|
||||
|
@ -65,13 +63,9 @@ pub struct Stderr(Mutex<State>);
|
|||
///
|
||||
/// [`Write`]: trait.Read.html
|
||||
/// [`Stderr::lock`]: struct.Stderr.html#method.lock
|
||||
#[cfg(feature = "unstable")]
|
||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
||||
#[derive(Debug)]
|
||||
pub struct StderrLock<'a>(std::io::StderrLock<'a>);
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
||||
unsafe impl Send for StderrLock<'_> {}
|
||||
|
||||
/// The state of the asynchronous stderr.
|
||||
|
@ -128,8 +122,6 @@ impl Stderr {
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
||||
#[cfg(any(feature = "unstable", feature = "docs"))]
|
||||
pub async fn lock(&self) -> StderrLock<'static> {
|
||||
static STDERR: Lazy<std::io::Stderr> = Lazy::new(std::io::stderr);
|
||||
|
||||
|
@ -240,8 +232,6 @@ cfg_windows! {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
||||
impl io::Write for StderrLock<'_> {
|
||||
fn poll_write(
|
||||
mut self: Pin<&mut Self>,
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Mutex;
|
||||
use std::io::Read as _;
|
||||
|
||||
use crate::future;
|
||||
use crate::io::{self, Read};
|
||||
use crate::task::{spawn_blocking, Context, JoinHandle, Poll};
|
||||
use crate::utils::Context as _;
|
||||
|
||||
cfg_unstable! {
|
||||
use once_cell::sync::Lazy;
|
||||
use std::io::Read as _;
|
||||
}
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
/// Constructs a new handle to the standard input of the current process.
|
||||
///
|
||||
|
@ -67,13 +65,9 @@ pub struct Stdin(Mutex<State>);
|
|||
///
|
||||
/// [`Read`]: trait.Read.html
|
||||
/// [`Stdin::lock`]: struct.Stdin.html#method.lock
|
||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
||||
#[cfg(feature = "unstable")]
|
||||
#[derive(Debug)]
|
||||
pub struct StdinLock<'a>(std::io::StdinLock<'a>);
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
||||
unsafe impl Send for StdinLock<'_> {}
|
||||
|
||||
/// The state of the asynchronous stdin.
|
||||
|
@ -187,8 +181,6 @@ impl Stdin {
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
||||
#[cfg(any(feature = "unstable", feature = "docs"))]
|
||||
pub async fn lock(&self) -> StdinLock<'static> {
|
||||
static STDIN: Lazy<std::io::Stdin> = Lazy::new(std::io::stdin);
|
||||
|
||||
|
@ -266,8 +258,6 @@ cfg_windows! {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
||||
impl Read for StdinLock<'_> {
|
||||
fn poll_read(
|
||||
mut self: Pin<&mut Self>,
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
use std::pin::Pin;
|
||||
use std::sync::Mutex;
|
||||
use std::future::Future;
|
||||
use std::io::Write as _;
|
||||
|
||||
use crate::io::{self, Write};
|
||||
use crate::task::{spawn_blocking, Context, JoinHandle, Poll};
|
||||
|
||||
cfg_unstable! {
|
||||
use once_cell::sync::Lazy;
|
||||
use std::io::Write as _;
|
||||
}
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
/// Constructs a new handle to the standard output of the current process.
|
||||
///
|
||||
|
@ -65,13 +63,9 @@ pub struct Stdout(Mutex<State>);
|
|||
///
|
||||
/// [`Write`]: trait.Read.html
|
||||
/// [`Stdout::lock`]: struct.Stdout.html#method.lock
|
||||
#[cfg(feature = "unstable")]
|
||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
||||
#[derive(Debug)]
|
||||
pub struct StdoutLock<'a>(std::io::StdoutLock<'a>);
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
||||
unsafe impl Send for StdoutLock<'_> {}
|
||||
|
||||
/// The state of the asynchronous stdout.
|
||||
|
@ -128,8 +122,6 @@ impl Stdout {
|
|||
/// #
|
||||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
||||
#[cfg(any(feature = "unstable", feature = "docs"))]
|
||||
pub async fn lock(&self) -> StdoutLock<'static> {
|
||||
static STDOUT: Lazy<std::io::Stdout> = Lazy::new(std::io::stdout);
|
||||
|
||||
|
@ -240,8 +232,6 @@ cfg_windows! {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
||||
impl Write for StdoutLock<'_> {
|
||||
fn poll_write(
|
||||
mut self: Pin<&mut Self>,
|
||||
|
|
Loading…
Reference in a new issue