Skip to content

Commit 721760a

Browse files
Remove stdio lock methods
Fixes #805.
1 parent 0ec027d commit 721760a

File tree

4 files changed

+0
-210
lines changed

4 files changed

+0
-210
lines changed

Diff for: src/io/mod.rs

-9
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,3 @@ cfg_default! {
328328
#[cfg(not(target_os = "unknown"))]
329329
mod stdout;
330330
}
331-
332-
cfg_unstable_default! {
333-
#[cfg(not(target_os = "unknown"))]
334-
pub use stderr::StderrLock;
335-
#[cfg(not(target_os = "unknown"))]
336-
pub use stdin::StdinLock;
337-
#[cfg(not(target_os = "unknown"))]
338-
pub use stdout::StdoutLock;
339-
}

Diff for: src/io/stderr.rs

-70
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ use std::future::Future;
55
use crate::io::{self, Write};
66
use crate::task::{spawn_blocking, Context, JoinHandle, Poll};
77

8-
cfg_unstable! {
9-
use once_cell::sync::Lazy;
10-
use std::io::Write as _;
11-
}
12-
138
/// Constructs a new handle to the standard error of the current process.
149
///
1510
/// This function is an async version of [`std::io::stderr`].
@@ -58,22 +53,6 @@ pub fn stderr() -> Stderr {
5853
#[derive(Debug)]
5954
pub struct Stderr(Mutex<State>);
6055

61-
/// A locked reference to the Stderr handle.
62-
///
63-
/// This handle implements the [`Write`] traits, and is constructed via the [`Stderr::lock`]
64-
/// method.
65-
///
66-
/// [`Write`]: trait.Read.html
67-
/// [`Stderr::lock`]: struct.Stderr.html#method.lock
68-
#[cfg(feature = "unstable")]
69-
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
70-
#[derive(Debug)]
71-
pub struct StderrLock<'a>(std::io::StderrLock<'a>);
72-
73-
#[cfg(feature = "unstable")]
74-
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
75-
unsafe impl Send for StderrLock<'_> {}
76-
7756
/// The state of the asynchronous stderr.
7857
///
7958
/// The stderr can be either idle or busy performing an asynchronous operation.
@@ -108,35 +87,6 @@ enum Operation {
10887
Flush(io::Result<()>),
10988
}
11089

111-
impl Stderr {
112-
/// Locks this handle to the standard error stream, returning a writable guard.
113-
///
114-
/// The lock is released when the returned lock goes out of scope. The returned guard also implements the Write trait for writing data.
115-
///
116-
/// # Examples
117-
///
118-
/// ```no_run
119-
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
120-
/// #
121-
/// use async_std::io;
122-
/// use async_std::prelude::*;
123-
///
124-
/// let stderr = io::stderr();
125-
/// let mut handle = stderr.lock().await;
126-
///
127-
/// handle.write_all(b"hello world").await?;
128-
/// #
129-
/// # Ok(()) }) }
130-
/// ```
131-
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
132-
#[cfg(any(feature = "unstable", feature = "docs"))]
133-
pub async fn lock(&self) -> StderrLock<'static> {
134-
static STDERR: Lazy<std::io::Stderr> = Lazy::new(std::io::stderr);
135-
136-
spawn_blocking(move || StderrLock(STDERR.lock())).await
137-
}
138-
}
139-
14090
impl Write for Stderr {
14191
fn poll_write(
14292
mut self: Pin<&mut Self>,
@@ -239,23 +189,3 @@ cfg_windows! {
239189
}
240190
}
241191
}
242-
243-
#[cfg(feature = "unstable")]
244-
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
245-
impl io::Write for StderrLock<'_> {
246-
fn poll_write(
247-
mut self: Pin<&mut Self>,
248-
_cx: &mut Context<'_>,
249-
buf: &[u8],
250-
) -> Poll<io::Result<usize>> {
251-
Poll::Ready(self.0.write(buf))
252-
}
253-
254-
fn poll_flush(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
255-
Poll::Ready(self.0.flush())
256-
}
257-
258-
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
259-
self.poll_flush(cx)
260-
}
261-
}

Diff for: src/io/stdin.rs

-61
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ use crate::io::{self, Read};
77
use crate::task::{spawn_blocking, Context, JoinHandle, Poll};
88
use crate::utils::Context as _;
99

10-
cfg_unstable! {
11-
use once_cell::sync::Lazy;
12-
use std::io::Read as _;
13-
}
14-
1510
/// Constructs a new handle to the standard input of the current process.
1611
///
1712
/// This function is an async version of [`std::io::stdin`].
@@ -61,21 +56,6 @@ pub fn stdin() -> Stdin {
6156
#[derive(Debug)]
6257
pub struct Stdin(Mutex<State>);
6358

64-
/// A locked reference to the Stdin handle.
65-
///
66-
/// This handle implements the [`Read`] traits, and is constructed via the [`Stdin::lock`] method.
67-
///
68-
/// [`Read`]: trait.Read.html
69-
/// [`Stdin::lock`]: struct.Stdin.html#method.lock
70-
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
71-
#[cfg(feature = "unstable")]
72-
#[derive(Debug)]
73-
pub struct StdinLock<'a>(std::io::StdinLock<'a>);
74-
75-
#[cfg(feature = "unstable")]
76-
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
77-
unsafe impl Send for StdinLock<'_> {}
78-
7959
/// The state of the asynchronous stdin.
8060
///
8161
/// The stdin can be either idle or busy performing an asynchronous operation.
@@ -165,35 +145,6 @@ impl Stdin {
165145
.await
166146
.context(|| String::from("could not read line on stdin"))
167147
}
168-
169-
/// Locks this handle to the standard input stream, returning a readable guard.
170-
///
171-
/// The lock is released when the returned lock goes out of scope. The returned guard also implements the Read trait for accessing the underlying data.
172-
///
173-
/// # Examples
174-
///
175-
/// ```no_run
176-
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
177-
/// #
178-
/// use async_std::io;
179-
/// use async_std::prelude::*;
180-
///
181-
/// let mut buffer = String::new();
182-
///
183-
/// let stdin = io::stdin();
184-
/// let mut handle = stdin.lock().await;
185-
///
186-
/// handle.read_to_string(&mut buffer).await?;
187-
/// #
188-
/// # Ok(()) }) }
189-
/// ```
190-
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
191-
#[cfg(any(feature = "unstable", feature = "docs"))]
192-
pub async fn lock(&self) -> StdinLock<'static> {
193-
static STDIN: Lazy<std::io::Stdin> = Lazy::new(std::io::stdin);
194-
195-
spawn_blocking(move || StdinLock(STDIN.lock())).await
196-
}
197148
}
198149

199150
impl Read for Stdin {
@@ -265,15 +216,3 @@ cfg_windows! {
265216
}
266217
}
267218
}
268-
269-
#[cfg(feature = "unstable")]
270-
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
271-
impl Read for StdinLock<'_> {
272-
fn poll_read(
273-
mut self: Pin<&mut Self>,
274-
_cx: &mut Context<'_>,
275-
buf: &mut [u8],
276-
) -> Poll<io::Result<usize>> {
277-
Poll::Ready(self.0.read(buf))
278-
}
279-
}

Diff for: src/io/stdout.rs

-70
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ use std::future::Future;
55
use crate::io::{self, Write};
66
use crate::task::{spawn_blocking, Context, JoinHandle, Poll};
77

8-
cfg_unstable! {
9-
use once_cell::sync::Lazy;
10-
use std::io::Write as _;
11-
}
12-
138
/// Constructs a new handle to the standard output of the current process.
149
///
1510
/// This function is an async version of [`std::io::stdout`].
@@ -58,22 +53,6 @@ pub fn stdout() -> Stdout {
5853
#[derive(Debug)]
5954
pub struct Stdout(Mutex<State>);
6055

61-
/// A locked reference to the Stderr handle.
62-
///
63-
/// This handle implements the [`Write`] traits, and is constructed via the [`Stdout::lock`]
64-
/// method.
65-
///
66-
/// [`Write`]: trait.Read.html
67-
/// [`Stdout::lock`]: struct.Stdout.html#method.lock
68-
#[cfg(feature = "unstable")]
69-
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
70-
#[derive(Debug)]
71-
pub struct StdoutLock<'a>(std::io::StdoutLock<'a>);
72-
73-
#[cfg(feature = "unstable")]
74-
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
75-
unsafe impl Send for StdoutLock<'_> {}
76-
7756
/// The state of the asynchronous stdout.
7857
///
7958
/// The stdout can be either idle or busy performing an asynchronous operation.
@@ -108,35 +87,6 @@ enum Operation {
10887
Flush(io::Result<()>),
10988
}
11089

111-
impl Stdout {
112-
/// Locks this handle to the standard error stream, returning a writable guard.
113-
///
114-
/// The lock is released when the returned lock goes out of scope. The returned guard also implements the Write trait for writing data.
115-
///
116-
/// # Examples
117-
///
118-
/// ```no_run
119-
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
120-
/// #
121-
/// use async_std::io;
122-
/// use async_std::prelude::*;
123-
///
124-
/// let stdout = io::stdout();
125-
/// let mut handle = stdout.lock().await;
126-
///
127-
/// handle.write_all(b"hello world").await?;
128-
/// #
129-
/// # Ok(()) }) }
130-
/// ```
131-
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
132-
#[cfg(any(feature = "unstable", feature = "docs"))]
133-
pub async fn lock(&self) -> StdoutLock<'static> {
134-
static STDOUT: Lazy<std::io::Stdout> = Lazy::new(std::io::stdout);
135-
136-
spawn_blocking(move || StdoutLock(STDOUT.lock())).await
137-
}
138-
}
139-
14090
impl Write for Stdout {
14191
fn poll_write(
14292
mut self: Pin<&mut Self>,
@@ -239,23 +189,3 @@ cfg_windows! {
239189
}
240190
}
241191
}
242-
243-
#[cfg(feature = "unstable")]
244-
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
245-
impl Write for StdoutLock<'_> {
246-
fn poll_write(
247-
mut self: Pin<&mut Self>,
248-
_cx: &mut Context<'_>,
249-
buf: &[u8],
250-
) -> Poll<io::Result<usize>> {
251-
Poll::Ready(self.0.write(buf))
252-
}
253-
254-
fn poll_flush(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
255-
Poll::Ready(self.0.flush())
256-
}
257-
258-
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
259-
self.poll_flush(cx)
260-
}
261-
}

0 commit comments

Comments
 (0)