Skip to content

Commit 019c808

Browse files
author
Stjepan Glavina
committed
Cleanup examples
1 parent ab51991 commit 019c808

37 files changed

+146
-67
lines changed

examples/list-dir.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
use std::env::args;
66

7-
use async_std::{fs, io, prelude::*, task};
7+
use async_std::fs;
8+
use async_std::io;
9+
use async_std::prelude::*;
10+
use async_std::task;
811

912
fn main() -> io::Result<()> {
1013
let path = args().nth(1).expect("missing path argument");

examples/print-file.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
use std::env::args;
66

7-
use async_std::{fs::File, io, prelude::*, task};
7+
use async_std::fs::File;
8+
use async_std::io;
9+
use async_std::prelude::*;
10+
use async_std::task;
811

912
const LEN: usize = 4 * 1024 * 1024; // 4 Mb
1013

examples/stdin-echo.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
33
#![feature(async_await)]
44

5-
use async_std::{io, prelude::*, task};
5+
use async_std::io;
6+
use async_std::prelude::*;
7+
use async_std::task;
68

79
fn main() -> io::Result<()> {
810
task::block_on(async {

examples/stdin-timeout.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use std::time::Duration;
66

7-
use async_std::{io, prelude::*, task};
7+
use async_std::io;
8+
use async_std::prelude::*;
9+
use async_std::task;
810

911
fn main() -> io::Result<()> {
1012
task::block_on(async {

examples/task-local.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
use std::cell::Cell;
66

7-
use async_std::{task, task_local};
7+
use async_std::prelude::*;
8+
use async_std::task;
89

910
task_local! {
1011
static VAR: Cell<i32> = Cell::new(1);

examples/tcp-client.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
1515
#![feature(async_await)]
1616

17-
use async_std::{io, net::TcpStream, prelude::*, task};
17+
use async_Std::prelude::*;
18+
use async_std::io;
19+
use async_std::net::TcpStream;
20+
use async_std::task;
1821

1922
fn main() -> io::Result<()> {
2023
task::block_on(async {

examples/tcp-echo.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
99
#![feature(async_await)]
1010

11+
use async_stD::task;
12+
use async_std::io;
1113
use async_std::net::{TcpListener, TcpStream};
12-
use async_std::{io, prelude::*, task};
14+
use async_std::prelude::*;
1315

1416
async fn process(stream: TcpStream) -> io::Result<()> {
1517
println!("Accepted from: {}", stream.peer_addr()?);

examples/udp-client.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
1515
#![feature(async_await)]
1616

17-
use async_std::{io, net::UdpSocket, task};
17+
use async_std::io;
18+
use async_std::net::UdpSocket;
19+
use async_std::task;
1820

1921
fn main() -> io::Result<()> {
2022
task::block_on(async {

examples/udp-echo.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
99
#![feature(async_await)]
1010

11-
use async_std::{io, net::UdpSocket, task};
11+
use async_std::io;
12+
use async_std::net::UdpSocket;
13+
use async_std::task;
1214

1315
fn main() -> io::Result<()> {
1416
task::block_on(async {

src/fs/dir_entry.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ impl DirEntry {
7777
/// # #![feature(async_await)]
7878
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
7979
/// #
80-
/// use async_std::{fs, prelude::*};
80+
/// use async_std::fs;
81+
/// use async_std::prelude::*;
8182
///
8283
/// let mut dir = fs::read_dir(".").await?;
8384
///
@@ -102,7 +103,8 @@ impl DirEntry {
102103
/// # #![feature(async_await)]
103104
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
104105
/// #
105-
/// use async_std::{fs, prelude::*};
106+
/// use async_std::fs;
107+
/// use async_std::prelude::*;
106108
///
107109
/// let mut dir = fs::read_dir(".").await?;
108110
///
@@ -155,7 +157,8 @@ impl DirEntry {
155157
/// # #![feature(async_await)]
156158
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
157159
/// #
158-
/// use async_std::{fs, prelude::*};
160+
/// use async_std::fs;
161+
/// use async_Std::prelude::*;
159162
///
160163
/// let mut dir = fs::read_dir(".").await?;
161164
///
@@ -206,7 +209,8 @@ impl DirEntry {
206209
/// # #![feature(async_await)]
207210
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
208211
/// #
209-
/// use async_std::{fs, prelude::*};
212+
/// use async_std::fs;
213+
/// use async_std::prelude::*;
210214
///
211215
/// let mut dir = fs::read_dir(".").await?;
212216
///

src/fs/read_dir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::fs;
2-
32
use std::path::Path;
43
use std::pin::Pin;
54
use std::sync::Mutex;
@@ -34,7 +33,8 @@ use crate::task::{blocking, Context, Poll};
3433
/// # #![feature(async_await)]
3534
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
3635
/// #
37-
/// use async_std::{fs, prelude::*};
36+
/// use async_std::fs;
37+
/// use async_std::prelude::*;
3838
///
3939
/// let mut dir = fs::read_dir(".").await?;
4040
///

src/fs/read_to_string.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ use crate::task::blocking;
2121
///
2222
/// ```no_run
2323
/// # #![feature(async_await)]
24-
/// use async_std::fs::read_to_string;
24+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
25+
/// #
26+
/// use async_std::fs;
2527
///
26-
/// # futures::executor::block_on(async {
27-
/// let contents = read_to_string("a.txt").await?;
28-
/// # std::io::Result::Ok(())
29-
/// # }).unwrap();
28+
/// let contents = fs::read_to_string("a.txt").await?;
29+
/// #
30+
/// # Ok(()) }) }
3031
/// ```
3132
pub async fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
3233
let path = path.as_ref().to_owned();

src/fs/set_permissions.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use crate::task::blocking;
2727
///
2828
/// let mut perm = fs::metadata("a.txt").await?.permissions();
2929
/// perm.set_readonly(true);
30-
///
3130
/// fs::set_permissions("a.txt", perm).await?;
3231
/// #
3332
/// # Ok(()) }) }

src/future/pending.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
/// # #![feature(async_await)]
66
/// # fn main() { async_std::task::block_on(async {
77
/// #
8+
/// use std::time::Duration;
9+
///
810
/// use async_std::future::pending;
911
/// use async_std::prelude::*;
10-
/// use std::time::Duration;
1112
///
1213
/// let dur = Duration::from_secs(1);
1314
/// assert!(pending::<()>().timeout(dur).await.is_err());

src/io/buf_read.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ pub trait BufRead {
4949
/// # #![feature(async_await)]
5050
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
5151
/// #
52-
/// use async_std::{fs::File, io::BufReader, prelude::*};
52+
/// use async_std::fs::File;
53+
/// use async_std::io::BufReader;
54+
/// use async_std::prelude::*;
5355
///
5456
/// let mut f = BufReader::new(File::open("a.txt").await?);
5557
///
@@ -98,7 +100,9 @@ pub trait BufRead {
98100
/// # #![feature(async_await)]
99101
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
100102
/// #
101-
/// use async_std::{fs::File, io::BufReader, prelude::*};
103+
/// use async_std::fs::File;
104+
/// use async_std::io::BufReader;
105+
/// use async_std::prelude::*;
102106
///
103107
/// let mut f = BufReader::new(File::open("a.txt").await?);
104108
///
@@ -137,7 +141,9 @@ pub trait BufRead {
137141
/// # #![feature(async_await)]
138142
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
139143
/// #
140-
/// use async_std::{fs::File, io::BufReader, prelude::*};
144+
/// use async_std::fs::File;
145+
/// use async_std::io::BufReader;
146+
/// use async_std::prelude::*;
141147
///
142148
/// let mut f = BufReader::new(File::open("a.txt").await?);
143149
///

src/io/copy.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ use crate::io;
3131
/// # #![feature(async_await)]
3232
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
3333
/// #
34-
/// use async_std::{io, task};
34+
/// use async_std::io;
35+
/// use async_std::task;
3536
///
3637
/// let mut reader: &[u8] = b"hello";
3738
/// let mut writer = io::stdout();

src/io/read.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ pub trait Read {
5555
/// # #![feature(async_await)]
5656
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
5757
/// #
58-
/// use async_std::{fs::File, prelude::*};
58+
/// use async_std::fs::File;
59+
/// use async_std::prelude::*;
5960
///
6061
/// let mut f = File::open("a.txt").await?;
6162
///
@@ -104,7 +105,8 @@ pub trait Read {
104105
/// # #![feature(async_await)]
105106
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
106107
/// #
107-
/// use async_std::{fs::File, prelude::*};
108+
/// use async_std::fs::File;
109+
/// use async_std::prelude::*;
108110
///
109111
/// let mut f = File::open("a.txt").await?;
110112
///
@@ -141,7 +143,8 @@ pub trait Read {
141143
/// # #![feature(async_await)]
142144
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
143145
/// #
144-
/// use async_std::{fs::File, prelude::*};
146+
/// use async_std::fs::File;
147+
/// use async_std::prelude::*;
145148
///
146149
/// let mut f = File::open("a.txt").await?;
147150
///
@@ -193,7 +196,8 @@ pub trait Read {
193196
/// # #![feature(async_await)]
194197
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
195198
/// #
196-
/// use async_std::{fs::File, prelude::*};
199+
/// use async_std::fs::File;
200+
/// use async_std::prelude::*;
197201
///
198202
/// let mut f = File::open("a.txt").await?;
199203
///

src/io/seek.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ pub trait Seek {
4747
/// # #![feature(async_await)]
4848
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
4949
/// #
50-
/// use async_std::{fs::File, io::SeekFrom, prelude::*};
50+
/// use async_std::fs::File;
51+
/// use async_std::io::SeekFrom;
52+
/// use async_std::prelude::*;
5153
///
5254
/// let mut f = File::open("a.txt").await?;
5355
///

src/io/stderr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ use crate::task::{blocking, Context, Poll};
1919
/// # #![feature(async_await)]
2020
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
2121
/// #
22-
/// use async_std::{io, prelude::*};
22+
/// use async_std::io;
23+
/// use async_std::prelude::*;
2324
///
2425
/// let mut stderr = io::stderr();
2526
/// stderr.write_all(b"Hello, world!").await?;

src/io/stdin.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,15 @@ impl Stdin {
9393
///
9494
/// ```no_run
9595
/// # #![feature(async_await)]
96-
/// use async_std::io::stdin;
96+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
97+
/// #
98+
/// use async_std::io;
9799
///
98-
/// # futures::executor::block_on(async {
99-
/// let stdin = stdin();
100+
/// let stdin = io::stdin();
100101
/// let mut line = String::new();
101102
/// stdin.read_line(&mut line).await?;
102-
/// # std::io::Result::Ok(())
103-
/// # }).unwrap();
103+
/// #
104+
/// # Ok(()) }) }
104105
/// ```
105106
pub async fn read_line(&self, buf: &mut String) -> io::Result<usize> {
106107
future::poll_fn(|cx| {

src/io/stdout.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ use crate::task::{blocking, Context, Poll};
1919
/// # #![feature(async_await)]
2020
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
2121
/// #
22-
/// use async_std::{io, prelude::*};
22+
/// use async_std::io;
23+
/// use async_std::prelude::*;
2324
///
2425
/// let mut stdout = io::stdout();
2526
/// stdout.write_all(b"Hello, world!").await?;

src/io/write.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ pub trait Write {
5050
/// # #![feature(async_await)]
5151
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
5252
/// #
53-
/// use async_std::{fs::File, prelude::*};
53+
/// use async_std::fs::File;
54+
/// use async_std::prelude::*;
5455
///
5556
/// let mut f = File::create("a.txt").await?;
5657
///
@@ -70,7 +71,8 @@ pub trait Write {
7071
/// # #![feature(async_await)]
7172
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
7273
/// #
73-
/// use async_std::{fs::File, prelude::*};
74+
/// use async_std::fs::File;
75+
/// use async_std::prelude::*;
7476
///
7577
/// let mut f = File::create("a.txt").await?;
7678
///
@@ -115,7 +117,8 @@ pub trait Write {
115117
/// # #![feature(async_await)]
116118
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
117119
/// #
118-
/// use async_std::{fs::File, prelude::*};
120+
/// use async_std::fs::File;
121+
/// use async_std::prelude::*;
119122
///
120123
/// let mut f = File::create("a.txt").await?;
121124
///

src/net/tcp/listener.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ use crate::task::{Context, Poll};
3333
/// # #![feature(async_await)]
3434
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
3535
/// #
36-
/// use async_std::{io, net::TcpListener, prelude::*};
36+
/// use async_std::io;
37+
/// use async_std::net::TcpListener;
38+
/// use async_std::prelude::*;
3739
///
3840
/// let listener = TcpListener::bind("127.0.0.1:8080").await?;
3941
/// let mut incoming = listener.incoming();
@@ -173,7 +175,8 @@ impl TcpListener {
173175
/// # #![feature(async_await)]
174176
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
175177
/// #
176-
/// use async_std::{net::TcpListener, prelude::*};
178+
/// use async_std::net::TcpListener;
179+
/// use async_std::prelude::*;
177180
///
178181
/// let listener = TcpListener::bind("127.0.0.1:0").await?;
179182
/// let mut incoming = listener.incoming();

0 commit comments

Comments
 (0)