From f9741e7488eb8b0ba63fc50e8fa43732002bac7b Mon Sep 17 00:00:00 2001 From: k-nasa Date: Tue, 15 Oct 2019 21:43:54 +0900 Subject: [PATCH 01/12] feat: Add Stderr::lock --- src/io/stderr.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/io/stderr.rs b/src/io/stderr.rs index 5706aa2ed..282d5e973 100644 --- a/src/io/stderr.rs +++ b/src/io/stderr.rs @@ -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>, From 9b0980659321f9b90bff21e435335d37de0434a4 Mon Sep 17 00:00:00 2001 From: k-nasa Date: Tue, 15 Oct 2019 21:44:11 +0900 Subject: [PATCH 02/12] feat: Add Stdin::lock --- src/io/stdin.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/io/stdin.rs b/src/io/stdin.rs index 95a77b805..f6c4a25ec 100644 --- a/src/io/stdin.rs +++ b/src/io/stdin.rs @@ -1,3 +1,4 @@ +use lazy_static::lazy_static; use std::pin::Pin; use std::sync::Mutex; @@ -134,6 +135,35 @@ impl Stdin { }) .await } + + /// Locks this handle to the standard input stream, returning a readable guard. + /// + /// The lock is released when the returned lock goes out of scope. The returned guard also implements the Read and BufRead traits for accessing the underlying data. + /// + /// # Examples + /// + /// ```no_run + /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # + /// use async_std::io; + /// use std::io::Read; + /// + /// let mut buffer = String::new(); + /// + /// let stdin = io::stdin(); + /// let mut handle = stdin.lock().await; + /// + /// handle.read_to_string(&mut buffer)?; + /// # + /// # Ok(()) }) } + /// ``` + pub async fn lock(&self) -> std::io::StdinLock<'static> { + lazy_static! { + static ref STDIN: std::io::Stdin = std::io::stdin(); + } + + STDIN.lock() + } } impl Read for Stdin { From 94ef3dc2b2cf0f32155e9643efd3a98c270a10f4 Mon Sep 17 00:00:00 2001 From: k-nasa Date: Tue, 15 Oct 2019 21:44:23 +0900 Subject: [PATCH 03/12] feat: Add Stdout::lock --- src/io/stdout.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/io/stdout.rs b/src/io/stdout.rs index 7849f1ce9..318013813 100644 --- a/src/io/stdout.rs +++ b/src/io/stdout.rs @@ -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 Stdout { + /// 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 stdout = io::stdout(); + /// let mut handle = stdout.lock().await; + /// + /// handle.write_all(b"hello world")?; + /// # + /// # Ok(()) }) } + /// ``` + pub async fn lock(&self) -> std::io::StdoutLock<'static> { + lazy_static! { + static ref STDOUT: std::io::Stdout = std::io::stdout(); + } + + STDOUT.lock() + } +} + impl Write for Stdout { fn poll_write( mut self: Pin<&mut Self>, From a5a00d7b1465b728592ae0cff55fbefba853d528 Mon Sep 17 00:00:00 2001 From: k-nasa Date: Thu, 17 Oct 2019 16:29:23 +0900 Subject: [PATCH 04/12] feat: Add StdinLock struct --- src/io/stdin.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/io/stdin.rs b/src/io/stdin.rs index f6c4a25ec..b4ccffbce 100644 --- a/src/io/stdin.rs +++ b/src/io/stdin.rs @@ -47,6 +47,11 @@ pub fn stdin() -> Stdin { #[derive(Debug)] pub struct Stdin(Mutex); +#[derive(Debug)] +pub struct StdinLock<'a>(std::io::StdinLock<'a>); + +unsafe impl Send for StdinLock<'_> {} + /// The state of the asynchronous stdin. /// /// The stdin can be either idle or busy performing an asynchronous operation. @@ -157,12 +162,14 @@ impl Stdin { /// # /// # Ok(()) }) } /// ``` - pub async fn lock(&self) -> std::io::StdinLock<'static> { + pub async fn lock(&self) -> StdinLock<'static> { lazy_static! { static ref STDIN: std::io::Stdin = std::io::stdin(); } - STDIN.lock() + blocking::spawn(async { + StdinLock(STDIN.lock()) + }).await } } @@ -248,3 +255,13 @@ cfg_if! { } } } + +impl Read for StdinLock<'_> { + fn poll_read( + self: Pin<&mut Self>, + _cx: &mut Context<'_>, + _buf: &mut [u8], + ) -> Poll> { + unimplemented!() + } +} From 70e84762643ec0877f03efc2e01514221f9bd116 Mon Sep 17 00:00:00 2001 From: k-nasa Date: Thu, 17 Oct 2019 16:32:14 +0900 Subject: [PATCH 05/12] fix StdinLock doc test --- src/io/stdin.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/io/stdin.rs b/src/io/stdin.rs index b4ccffbce..4201a3a01 100644 --- a/src/io/stdin.rs +++ b/src/io/stdin.rs @@ -151,14 +151,14 @@ impl Stdin { /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { /// # /// use async_std::io; - /// use std::io::Read; + /// use crate::async_std::prelude::*; /// /// let mut buffer = String::new(); /// /// let stdin = io::stdin(); /// let mut handle = stdin.lock().await; /// - /// handle.read_to_string(&mut buffer)?; + /// handle.read_to_string(&mut buffer).await?; /// # /// # Ok(()) }) } /// ``` From f2bf01223c51702532e48ba6f8629d4202028a6b Mon Sep 17 00:00:00 2001 From: k-nasa Date: Thu, 17 Oct 2019 16:34:39 +0900 Subject: [PATCH 06/12] $cargo fmt --- src/io/stdin.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/io/stdin.rs b/src/io/stdin.rs index 4201a3a01..daba03e86 100644 --- a/src/io/stdin.rs +++ b/src/io/stdin.rs @@ -167,9 +167,7 @@ impl Stdin { static ref STDIN: std::io::Stdin = std::io::stdin(); } - blocking::spawn(async { - StdinLock(STDIN.lock()) - }).await + blocking::spawn(async { StdinLock(STDIN.lock()) }).await } } From 59615a655bc91bd48fc365015a85f73e3a7b9083 Mon Sep 17 00:00:00 2001 From: k-nasa Date: Sun, 27 Oct 2019 21:48:23 +0900 Subject: [PATCH 07/12] feat: Add StderrLock and StdoutLock struct --- src/io/stderr.rs | 27 +++++++++++++++++++++++++-- src/io/stdin.rs | 2 +- src/io/stdout.rs | 27 +++++++++++++++++++++++++-- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/io/stderr.rs b/src/io/stderr.rs index 8193eeb7d..1ea33616e 100644 --- a/src/io/stderr.rs +++ b/src/io/stderr.rs @@ -44,6 +44,11 @@ pub fn stderr() -> Stderr { #[derive(Debug)] pub struct Stderr(Mutex); +#[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> { + unimplemented!() + } + + fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll> { + unimplemented!() + } + + fn poll_close(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll> { + unimplemented!() + } +} diff --git a/src/io/stdin.rs b/src/io/stdin.rs index 93d91700e..f869cbf64 100644 --- a/src/io/stdin.rs +++ b/src/io/stdin.rs @@ -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 } } diff --git a/src/io/stdout.rs b/src/io/stdout.rs index cbe14b8bf..360bfe86a 100644 --- a/src/io/stdout.rs +++ b/src/io/stdout.rs @@ -44,6 +44,11 @@ pub fn stdout() -> Stdout { #[derive(Debug)] pub struct Stdout(Mutex); +#[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> { + unimplemented!() + } + + fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll> { + unimplemented!() + } + + fn poll_close(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll> { + unimplemented!() + } +} From 2c91b30ee8613b3ac0319513996ce7b8c9ee8782 Mon Sep 17 00:00:00 2001 From: k-nasa Date: Tue, 29 Oct 2019 23:02:18 +0900 Subject: [PATCH 08/12] feat: Add Read and Write trait to Lock struct --- src/io/mod.rs | 6 +++--- src/io/stderr.rs | 24 +++++++++++++++--------- src/io/stdin.rs | 15 +++++++++++---- src/io/stdout.rs | 24 +++++++++++++++--------- 4 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/io/mod.rs b/src/io/mod.rs index 9a125b20b..c81d82f95 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -282,9 +282,9 @@ pub use read::Read; pub use repeat::{repeat, Repeat}; pub use seek::Seek; pub use sink::{sink, Sink}; -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; pub use write::Write; diff --git a/src/io/stderr.rs b/src/io/stderr.rs index 7cd95aa5d..4e727f210 100644 --- a/src/io/stderr.rs +++ b/src/io/stderr.rs @@ -1,4 +1,5 @@ use lazy_static::lazy_static; +use std::io::Write as StdWrite; use std::pin::Pin; use std::sync::Mutex; @@ -54,6 +55,11 @@ pub fn stderr() -> Stderr { #[derive(Debug)] pub struct Stderr(Mutex); +/// A locked reference to the Stderr handle. +/// This handle implements the [`Write`] traits, and is constructed via the [`Stderr::lock`] method. +/// +/// [`Write`]: trait.Read.html +/// [`Stderr::lock`]: struct.Stderr.html#method.lock #[derive(Debug)] pub struct StderrLock<'a>(std::io::StderrLock<'a>); @@ -104,12 +110,12 @@ impl Stderr { /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { /// # /// use async_std::io; - /// use std::io::Write; + /// use async_std::prelude::*; /// /// let stderr = io::stderr(); /// let mut handle = stderr.lock().await; /// - /// handle.write_all(b"hello world")?; + /// handle.write_all(b"hello world").await?; /// # /// # Ok(()) }) } /// ``` @@ -227,18 +233,18 @@ cfg_windows! { impl Write for StderrLock<'_> { fn poll_write( - self: Pin<&mut Self>, + mut self: Pin<&mut Self>, _cx: &mut Context<'_>, - _buf: &[u8], + buf: &[u8], ) -> Poll> { - unimplemented!() + Poll::Ready(self.0.write(buf)) } - fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll> { - unimplemented!() + fn poll_flush(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll> { + Poll::Ready(self.0.flush()) } - fn poll_close(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll> { - unimplemented!() + fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + self.poll_flush(cx) } } diff --git a/src/io/stdin.rs b/src/io/stdin.rs index 82a0b00b1..9fb28bab8 100644 --- a/src/io/stdin.rs +++ b/src/io/stdin.rs @@ -55,6 +55,11 @@ pub fn stdin() -> Stdin { #[derive(Debug)] pub struct Stdin(Mutex); +/// A locked reference to the Stdin handle. +/// This handle implements the [`Read`] traits, and is constructed via the [`Stdin::lock`] method. +/// +/// [`Read`]: trait.Read.html +/// [`Stdin::lock`]: struct.Stdin.html#method.lock #[derive(Debug)] pub struct StdinLock<'a>(std::io::StdinLock<'a>); @@ -151,7 +156,7 @@ impl Stdin { /// Locks this handle to the standard input stream, returning a readable guard. /// - /// The lock is released when the returned lock goes out of scope. The returned guard also implements the Read and BufRead traits for accessing the underlying data. + /// 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. /// /// # Examples /// @@ -251,10 +256,12 @@ cfg_windows! { impl Read for StdinLock<'_> { fn poll_read( - self: Pin<&mut Self>, + mut self: Pin<&mut Self>, _cx: &mut Context<'_>, - _buf: &mut [u8], + buf: &mut [u8], ) -> Poll> { - unimplemented!() + use std::io::Read as StdRead; + + Poll::Ready(self.0.read(buf)) } } diff --git a/src/io/stdout.rs b/src/io/stdout.rs index 8d4ba273c..c314837bb 100644 --- a/src/io/stdout.rs +++ b/src/io/stdout.rs @@ -1,4 +1,5 @@ use lazy_static::lazy_static; +use std::io::Write as StdWrite; use std::pin::Pin; use std::sync::Mutex; @@ -54,6 +55,11 @@ pub fn stdout() -> Stdout { #[derive(Debug)] pub struct Stdout(Mutex); +/// A locked reference to the Stderr handle. +/// This handle implements the [`Write`] traits, and is constructed via the [`Stdout::lock`] method. +/// +/// [`Write`]: trait.Read.html +/// [`Stdout::lock`]: struct.Stdout.html#method.lock #[derive(Debug)] pub struct StdoutLock<'a>(std::io::StdoutLock<'a>); @@ -104,12 +110,12 @@ impl Stdout { /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { /// # /// use async_std::io; - /// use std::io::Write; + /// use async_std::prelude::*; /// /// let stdout = io::stdout(); /// let mut handle = stdout.lock().await; /// - /// handle.write_all(b"hello world")?; + /// handle.write_all(b"hello world").await?; /// # /// # Ok(()) }) } /// ``` @@ -227,18 +233,18 @@ cfg_windows! { impl Write for StdoutLock<'_> { fn poll_write( - self: Pin<&mut Self>, + mut self: Pin<&mut Self>, _cx: &mut Context<'_>, - _buf: &[u8], + buf: &[u8], ) -> Poll> { - unimplemented!() + Poll::Ready(self.0.write(buf)) } - fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll> { - unimplemented!() + fn poll_flush(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll> { + Poll::Ready(self.0.flush()) } - fn poll_close(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll> { - unimplemented!() + fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + self.poll_flush(cx) } } From eeb44c86e9adfcf2fca7d85dbffaaf96b337efdc Mon Sep 17 00:00:00 2001 From: k-nasa Date: Fri, 1 Nov 2019 10:34:28 +0900 Subject: [PATCH 09/12] fix --- src/io/stderr.rs | 6 ++---- src/io/stdin.rs | 6 ++---- src/io/stdout.rs | 6 ++---- src/stream/stream/min.rs | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/io/stderr.rs b/src/io/stderr.rs index 4e727f210..7584dc1ba 100644 --- a/src/io/stderr.rs +++ b/src/io/stderr.rs @@ -1,4 +1,4 @@ -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::io::Write as StdWrite; use std::pin::Pin; use std::sync::Mutex; @@ -120,9 +120,7 @@ impl Stderr { /// # Ok(()) }) } /// ``` pub async fn lock(&self) -> StderrLock<'static> { - lazy_static! { - static ref STDERR: std::io::Stderr = std::io::stderr(); - } + static STDERR: Lazy = Lazy::new(|| std::io::stderr()); blocking::spawn(move || StderrLock(STDERR.lock())).await } diff --git a/src/io/stdin.rs b/src/io/stdin.rs index 9fb28bab8..359f2a349 100644 --- a/src/io/stdin.rs +++ b/src/io/stdin.rs @@ -1,4 +1,4 @@ -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::pin::Pin; use std::sync::Mutex; @@ -176,9 +176,7 @@ impl Stdin { /// # Ok(()) }) } /// ``` pub async fn lock(&self) -> StdinLock<'static> { - lazy_static! { - static ref STDIN: std::io::Stdin = std::io::stdin(); - } + static STDIN: Lazy = Lazy::new(|| std::io::stdin()); blocking::spawn(move || StdinLock(STDIN.lock())).await } diff --git a/src/io/stdout.rs b/src/io/stdout.rs index c314837bb..ccfd85b23 100644 --- a/src/io/stdout.rs +++ b/src/io/stdout.rs @@ -1,4 +1,4 @@ -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::io::Write as StdWrite; use std::pin::Pin; use std::sync::Mutex; @@ -120,9 +120,7 @@ impl Stdout { /// # Ok(()) }) } /// ``` pub async fn lock(&self) -> StdoutLock<'static> { - lazy_static! { - static ref STDOUT: std::io::Stdout = std::io::stdout(); - } + static STDOUT: Lazy = Lazy::new(|| std::io::stdout()); blocking::spawn(move || StdoutLock(STDOUT.lock())).await } diff --git a/src/stream/stream/min.rs b/src/stream/stream/min.rs index 1ab56065d..b4a8c7c16 100644 --- a/src/stream/stream/min.rs +++ b/src/stream/stream/min.rs @@ -1,5 +1,5 @@ +use std::cmp::{Ord, Ordering}; use std::marker::PhantomData; -use std::cmp::{Ordering, Ord}; use std::pin::Pin; use pin_project_lite::pin_project; From caa23381f0e8471e2d5251bd2b71ae073f5076ba Mon Sep 17 00:00:00 2001 From: k-nasa Date: Fri, 1 Nov 2019 10:41:21 +0900 Subject: [PATCH 10/12] fix clippy warning --- src/io/stderr.rs | 2 +- src/io/stdin.rs | 2 +- src/io/stdout.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/io/stderr.rs b/src/io/stderr.rs index 7584dc1ba..334e50adc 100644 --- a/src/io/stderr.rs +++ b/src/io/stderr.rs @@ -120,7 +120,7 @@ impl Stderr { /// # Ok(()) }) } /// ``` pub async fn lock(&self) -> StderrLock<'static> { - static STDERR: Lazy = Lazy::new(|| std::io::stderr()); + static STDERR: Lazy = Lazy::new(std::io::stderr); blocking::spawn(move || StderrLock(STDERR.lock())).await } diff --git a/src/io/stdin.rs b/src/io/stdin.rs index 359f2a349..8480c69da 100644 --- a/src/io/stdin.rs +++ b/src/io/stdin.rs @@ -176,7 +176,7 @@ impl Stdin { /// # Ok(()) }) } /// ``` pub async fn lock(&self) -> StdinLock<'static> { - static STDIN: Lazy = Lazy::new(|| std::io::stdin()); + static STDIN: Lazy = Lazy::new(std::io::stdin); blocking::spawn(move || StdinLock(STDIN.lock())).await } diff --git a/src/io/stdout.rs b/src/io/stdout.rs index ccfd85b23..aaa99ceb9 100644 --- a/src/io/stdout.rs +++ b/src/io/stdout.rs @@ -120,7 +120,7 @@ impl Stdout { /// # Ok(()) }) } /// ``` pub async fn lock(&self) -> StdoutLock<'static> { - static STDOUT: Lazy = Lazy::new(|| std::io::stdout()); + static STDOUT: Lazy = Lazy::new(std::io::stdout); blocking::spawn(move || StdoutLock(STDOUT.lock())).await } From 81873ae5f3a0ea31bc20373c62e9c2b1ebe359ad Mon Sep 17 00:00:00 2001 From: k-nasa Date: Sat, 2 Nov 2019 01:27:27 +0900 Subject: [PATCH 11/12] fix --- src/io/stderr.rs | 2 +- src/io/stdin.rs | 2 +- src/io/stdout.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/io/stderr.rs b/src/io/stderr.rs index b3cc71138..8986d48d3 100644 --- a/src/io/stderr.rs +++ b/src/io/stderr.rs @@ -122,7 +122,7 @@ impl Stderr { pub async fn lock(&self) -> StderrLock<'static> { static STDERR: Lazy = Lazy::new(std::io::stderr); - blocking::spawn(move || StderrLock(STDERR.lock())).await + spawn_blocking(move || StderrLock(STDERR.lock())).await } } diff --git a/src/io/stdin.rs b/src/io/stdin.rs index a72d05595..d7b26909f 100644 --- a/src/io/stdin.rs +++ b/src/io/stdin.rs @@ -178,7 +178,7 @@ impl Stdin { pub async fn lock(&self) -> StdinLock<'static> { static STDIN: Lazy = Lazy::new(std::io::stdin); - blocking::spawn(move || StdinLock(STDIN.lock())).await + spawn_blocking(move || StdinLock(STDIN.lock())).await } } diff --git a/src/io/stdout.rs b/src/io/stdout.rs index 99c636d67..c6281d776 100644 --- a/src/io/stdout.rs +++ b/src/io/stdout.rs @@ -122,7 +122,7 @@ impl Stdout { pub async fn lock(&self) -> StdoutLock<'static> { static STDOUT: Lazy = Lazy::new(std::io::stdout); - blocking::spawn(move || StdoutLock(STDOUT.lock())).await + spawn_blocking(move || StdoutLock(STDOUT.lock())).await } } From 3dcad984b4c492196118cc6249e2d79b0415a279 Mon Sep 17 00:00:00 2001 From: k-nasa Date: Sat, 2 Nov 2019 12:29:54 +0900 Subject: [PATCH 12/12] fix: To unstable feature --- src/io/stderr.rs | 7 ++++++- src/io/stdin.rs | 7 ++++++- src/io/stdout.rs | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/io/stderr.rs b/src/io/stderr.rs index 8986d48d3..a0d9b7135 100644 --- a/src/io/stderr.rs +++ b/src/io/stderr.rs @@ -1,4 +1,3 @@ -use once_cell::sync::Lazy; use std::io::Write as StdWrite; use std::pin::Pin; use std::sync::Mutex; @@ -7,6 +6,10 @@ use crate::future::Future; use crate::io::{self, Write}; use crate::task::{spawn_blocking, Context, JoinHandle, Poll}; +cfg_unstable! { + use once_cell::sync::Lazy; +} + /// Constructs a new handle to the standard error of the current process. /// /// This function is an async version of [`std::io::stderr`]. @@ -119,6 +122,8 @@ 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 = Lazy::new(std::io::stderr); diff --git a/src/io/stdin.rs b/src/io/stdin.rs index d7b26909f..e5bb508d5 100644 --- a/src/io/stdin.rs +++ b/src/io/stdin.rs @@ -1,4 +1,3 @@ -use once_cell::sync::Lazy; use std::pin::Pin; use std::sync::Mutex; @@ -6,6 +5,10 @@ use crate::future::{self, Future}; use crate::io::{self, Read}; use crate::task::{spawn_blocking, Context, JoinHandle, Poll}; +cfg_unstable! { + use once_cell::sync::Lazy; +} + /// Constructs a new handle to the standard input of the current process. /// /// This function is an async version of [`std::io::stdin`]. @@ -175,6 +178,8 @@ 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 = Lazy::new(std::io::stdin); diff --git a/src/io/stdout.rs b/src/io/stdout.rs index c6281d776..bf22128fc 100644 --- a/src/io/stdout.rs +++ b/src/io/stdout.rs @@ -1,4 +1,3 @@ -use once_cell::sync::Lazy; use std::io::Write as StdWrite; use std::pin::Pin; use std::sync::Mutex; @@ -7,6 +6,10 @@ use crate::future::Future; use crate::io::{self, Write}; use crate::task::{spawn_blocking, Context, JoinHandle, Poll}; +cfg_unstable! { + use once_cell::sync::Lazy; +} + /// Constructs a new handle to the standard output of the current process. /// /// This function is an async version of [`std::io::stdout`]. @@ -119,6 +122,8 @@ 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 = Lazy::new(std::io::stdout);