Skip to content

Commit 61f9483

Browse files
authored
Merge pull request async-rs#719 from k-nasa/remove_re_export
Stabilize most stream method and remove unnecessary macros
2 parents 9167d42 + f33d7f4 commit 61f9483

34 files changed

+110
-1192
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ default = [
2626
"async-task",
2727
"crossbeam-channel",
2828
"crossbeam-deque",
29-
"futures-timer",
3029
"kv-log-macro",
3130
"log",
3231
"mio",
@@ -35,13 +34,14 @@ default = [
3534
"pin-project-lite",
3635
]
3736
docs = ["attributes", "unstable", "default"]
38-
unstable = ["std", "broadcaster", "futures-timer"]
37+
unstable = ["std", "broadcaster"]
3938
attributes = ["async-attributes"]
4039
std = [
4140
"alloc",
4241
"crossbeam-utils",
4342
"futures-core/std",
4443
"futures-io",
44+
"futures-timer",
4545
"memchr",
4646
"once_cell",
4747
"pin-utils",

examples/a-chat/client.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use futures::select;
22
use futures::FutureExt;
3+
use std::io::{self, BufRead, BufReader as StdBufReader};
34

45
use async_std::{
5-
io::{stdin, BufReader},
6+
io::BufReader,
67
net::{TcpStream, ToSocketAddrs},
78
prelude::*,
8-
task,
9+
stream, task,
910
};
1011

1112
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
@@ -20,8 +21,9 @@ async fn try_main(addr: impl ToSocketAddrs) -> Result<()> {
2021
let reader = BufReader::new(reader);
2122
let mut lines_from_server = futures::StreamExt::fuse(reader.lines());
2223

23-
let stdin = BufReader::new(stdin());
24-
let mut lines_from_stdin = futures::StreamExt::fuse(stdin.lines());
24+
let stdin = StdBufReader::new(io::stdin());
25+
let mut lines_from_stdin = stream::from_iter(stdin.lines());
26+
2527
loop {
2628
select! {
2729
line = lines_from_server.next().fuse() => match line {

examples/print-file.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Prints a file given as an argument to stdout.
22
33
use std::env::args;
4+
use std::io::Write;
45

56
use async_std::fs::File;
67
use async_std::io;
@@ -14,7 +15,7 @@ fn main() -> io::Result<()> {
1415

1516
task::block_on(async {
1617
let mut file = File::open(&path).await?;
17-
let mut stdout = io::stdout();
18+
let mut stdout = std::io::stdout();
1819
let mut buf = vec![0u8; LEN];
1920

2021
loop {
@@ -23,12 +24,12 @@ fn main() -> io::Result<()> {
2324

2425
// If this is the end of file, clean up and return.
2526
if n == 0 {
26-
stdout.flush().await?;
27+
stdout.flush()?;
2728
return Ok(());
2829
}
2930

3031
// Write the buffer into stdout.
31-
stdout.write_all(&buf[..n]).await?;
32+
stdout.write_all(&buf[..n])?;
3233
}
3334
})
3435
}

examples/stdin-echo.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
//! Echoes lines read on stdin to stdout.
22
33
use async_std::io;
4-
use async_std::prelude::*;
54
use async_std::task;
5+
use std::io::Write;
66

77
fn main() -> io::Result<()> {
88
task::block_on(async {
9-
let stdin = io::stdin();
10-
let mut stdout = io::stdout();
9+
let stdin = std::io::stdin();
10+
let mut stdout = std::io::stdout();
1111
let mut line = String::new();
1212

1313
loop {
1414
// Read a line from stdin.
15-
let n = stdin.read_line(&mut line).await?;
15+
let n = stdin.read_line(&mut line)?;
1616

1717
// If this is the end of stdin, return.
1818
if n == 0 {
1919
return Ok(());
2020
}
2121

2222
// Write the line to stdout.
23-
stdout.write_all(line.as_bytes()).await?;
24-
stdout.flush().await?;
23+
stdout.write_all(line.as_bytes())?;
24+
stdout.flush()?;
2525
line.clear();
2626
}
2727
})

examples/stdin-timeout.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use async_std::task;
88
fn main() -> io::Result<()> {
99
// This async scope times out after 5 seconds.
1010
task::block_on(io::timeout(Duration::from_secs(5), async {
11-
let stdin = io::stdin();
11+
let stdin = std::io::stdin();
1212

1313
// Read a line from the standard input and display it.
1414
let mut line = String::new();
15-
stdin.read_line(&mut line).await?;
15+
stdin.read_line(&mut line)?;
1616
dbg!(line);
1717

1818
Ok(())

src/future/into_future.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ use std::future::Future;
55
/// # Examples
66
///
77
/// ```
8+
/// use std::pin::Pin;
9+
///
810
/// use async_std::future::{Future, IntoFuture};
911
/// use async_std::io;
10-
/// use async_std::pin::Pin;
1112
///
1213
/// struct Client;
1314
///

src/future/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ cfg_std! {
6363

6464
cfg_default! {
6565
pub use timeout::{timeout, TimeoutError};
66+
6667
mod timeout;
6768
}
6869

6970
cfg_unstable! {
7071
pub use into_future::IntoFuture;
7172
pub(crate) use maybe_done::MaybeDone;
73+
7274
mod into_future;
7375
mod maybe_done;
7476
}

src/io/copy.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ use crate::utils::Context as _;
3232
///
3333
/// # Examples
3434
///
35-
/// ```
35+
/// ```no_run
3636
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
3737
/// #
3838
/// use async_std::io;
39+
/// use async_std::fs::File;
3940
///
4041
/// let mut reader: &[u8] = b"hello";
41-
/// let mut writer = io::stdout();
42+
/// let mut writer = File::open("foo.txt").await?;
4243
///
4344
/// io::copy(&mut reader, &mut writer).await?;
4445
/// #
@@ -119,13 +120,14 @@ where
119120
///
120121
/// # Examples
121122
///
122-
/// ```
123+
/// ```no_run
123124
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
124125
/// #
125126
/// use async_std::io;
127+
/// use async_std::fs::File;
126128
///
127129
/// let mut reader: &[u8] = b"hello";
128-
/// let mut writer = io::stdout();
130+
/// let mut writer = File::open("foo.txt").await?;
129131
///
130132
/// io::copy(&mut reader, &mut writer).await?;
131133
/// #

src/io/mod.rs

+10-74
Original file line numberDiff line numberDiff line change
@@ -122,56 +122,6 @@
122122
//! # Ok(()) }) }
123123
//! ```
124124
//!
125-
//! ## Standard input and output
126-
//!
127-
//! A very common source of input is standard input:
128-
//!
129-
//! ```no_run
130-
//! use async_std::io;
131-
//!
132-
//! # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
133-
//! #
134-
//! let mut input = String::new();
135-
//!
136-
//! io::stdin().read_line(&mut input).await?;
137-
//!
138-
//! println!("You typed: {}", input.trim());
139-
//! #
140-
//! # Ok(()) }) }
141-
//! ```
142-
//!
143-
//! Note that you cannot use the [`?` operator] in functions that do not return
144-
//! a [`Result<T, E>`][`Result`]. Instead, you can call [`.unwrap()`]
145-
//! or `match` on the return value to catch any possible errors:
146-
//!
147-
//! ```no_run
148-
//! use async_std::io;
149-
//!
150-
//! # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
151-
//! #
152-
//! let mut input = String::new();
153-
//!
154-
//! io::stdin().read_line(&mut input).await.unwrap();
155-
//! #
156-
//! # Ok(()) }) }
157-
//! ```
158-
//!
159-
//! And a very common source of output is standard output:
160-
//!
161-
//! ```no_run
162-
//! use async_std::io;
163-
//! use async_std::io::prelude::*;
164-
//!
165-
//! # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
166-
//! #
167-
//! io::stdout().write(&[42]).await?;
168-
//! #
169-
//! # Ok(()) }) }
170-
//! ```
171-
//!
172-
//! Of course, using [`io::stdout`] directly is less common than something like
173-
//! [`println!`].
174-
//!
175125
//! ## Iterator types
176126
//!
177127
//! A large number of the structures provided by `std::io` are for various
@@ -204,10 +154,14 @@
204154
//!
205155
//! ```no_run
206156
//! use async_std::io;
157+
//! use async_std::fs::File;
207158
//!
208159
//! # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
209160
//! #
210-
//! io::copy(&mut io::stdin(), &mut io::stdout()).await?;
161+
//! let mut reader: &[u8] = b"hello";
162+
//! let mut writer = File::open("foo.txt").await?;
163+
//!
164+
//! io::copy(&mut reader, &mut writer).await?;
211165
//! #
212166
//! # Ok(()) }) }
213167
//! ```
@@ -224,13 +178,14 @@
224178
//! ```
225179
//! #![allow(dead_code)]
226180
//! use async_std::io;
181+
//! use std::time::Duration;
227182
//!
228183
//! async fn read_input() -> io::Result<()> {
229-
//! let mut input = String::new();
230-
//!
231-
//! io::stdin().read_line(&mut input).await?;
184+
//! let f = io::timeout(Duration::from_secs(5), async {
185+
//! Ok(())
186+
//! });
232187
//!
233-
//! println!("You typed: {}", input.trim());
188+
//! assert_eq!(f.await?, ());
234189
//!
235190
//! Ok(())
236191
//! }
@@ -260,8 +215,6 @@
260215
//! [`BufReader`]: struct.BufReader.html
261216
//! [`BufWriter`]: struct.BufWriter.html
262217
//! [`Write::write`]: trait.Write.html#tymethod.write
263-
//! [`io::stdout`]: fn.stdout.html
264-
//! [`println!`]: ../macro.println.html
265218
//! [`Lines`]: struct.Lines.html
266219
//! [`io::Result`]: type.Result.html
267220
//! [`?` operator]: https://doc.rust-lang.org/stable/book/appendix-02-operators.html
@@ -305,24 +258,7 @@ cfg_std! {
305258
}
306259

307260
cfg_default! {
308-
// For use in the print macros.
309-
#[doc(hidden)]
310-
pub use stdio::{_eprint, _print};
311-
312-
pub use stderr::{stderr, Stderr};
313-
pub use stdin::{stdin, Stdin};
314-
pub use stdout::{stdout, Stdout};
315261
pub use timeout::timeout;
316262

317263
mod timeout;
318-
mod stderr;
319-
mod stdin;
320-
mod stdio;
321-
mod stdout;
322-
}
323-
324-
cfg_unstable_default! {
325-
pub use stderr::StderrLock;
326-
pub use stdin::StdinLock;
327-
pub use stdout::StdoutLock;
328264
}

0 commit comments

Comments
 (0)