Skip to content

Commit 63c2c75

Browse files
committed
migrate: std::net::ToSocketAddrs -> async_std::net::ToSocketAddrs
1 parent 242cc9f commit 63c2c75

File tree

6 files changed

+17
-29
lines changed

6 files changed

+17
-29
lines changed

docs/src/tutorial/accept_loop.md

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,20 @@ First of all, let's add required import boilerplate:
66

77
```rust,edition2018
88
# extern crate async_std;
9-
use std::net::ToSocketAddrs; // 1
109
use async_std::{
11-
prelude::*, // 2
12-
task, // 3
13-
net::TcpListener, // 4
10+
prelude::*, // 1
11+
task, // 2
12+
net::{TcpListener, ToSocketAddrs}, // 3
1413
};
1514
16-
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>; // 5
15+
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>; // 4
1716
```
1817

19-
1. `async_std` uses `std` types where appropriate.
20-
We'll need `ToSocketAddrs` to specify address to listen on.
21-
2. `prelude` re-exports some traits required to work with futures and streams.
22-
3. The `task` module roughly corresponds to the `std::thread` module, but tasks are much lighter weight.
18+
1. `prelude` re-exports some traits required to work with futures and streams.
19+
2. The `task` module roughly corresponds to the `std::thread` module, but tasks are much lighter weight.
2320
A single thread can run many tasks.
24-
4. For the socket type, we use `TcpListener` from `async_std`, which is just like `std::net::TcpListener`, but is non-blocking and uses `async` API.
25-
5. We will skip implementing comprehensive error handling in this example.
21+
3. For the socket type, we use `TcpListener` from `async_std`, which is just like `std::net::TcpListener`, but is non-blocking and uses `async` API.
22+
4. We will skip implementing comprehensive error handling in this example.
2623
To propagate the errors, we will use a boxed error trait object.
2724
Do you know that there's `From<&'_ str> for Box<dyn Error>` implementation in stdlib, which allows you to use strings with `?` operator?
2825

@@ -31,10 +28,9 @@ Now we can write the server's accept loop:
3128
```rust,edition2018
3229
# extern crate async_std;
3330
# use async_std::{
34-
# net::TcpListener,
31+
# net::{TcpListener, ToSocketAddrs},
3532
# prelude::Stream,
3633
# };
37-
# use std::net::ToSocketAddrs;
3834
#
3935
# type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
4036
#
@@ -69,11 +65,10 @@ Finally, let's add main:
6965
```rust,edition2018
7066
# extern crate async_std;
7167
# use async_std::{
72-
# net::TcpListener,
68+
# net::{TcpListener, ToSocketAddrs},
7369
# prelude::Stream,
7470
# task,
7571
# };
76-
# use std::net::ToSocketAddrs;
7772
#
7873
# type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
7974
#

docs/src/tutorial/all_together.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ At this point, we only need to start the broker to get a fully-functioning (in t
77
# extern crate futures;
88
use async_std::{
99
io::{self, BufReader},
10-
net::{TcpListener, TcpStream},
10+
net::{TcpListener, TcpStream, ToSocketAddrs},
1111
prelude::*,
1212
task,
1313
};
@@ -17,7 +17,6 @@ use futures::{
1717
};
1818
use std::{
1919
collections::hash_map::{HashMap, Entry},
20-
net::ToSocketAddrs,
2120
sync::Arc,
2221
};
2322

docs/src/tutorial/clean_shutdown.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Let's add waiting to the server:
2525
# extern crate futures;
2626
# use async_std::{
2727
# io::{self, BufReader},
28-
# net::{TcpListener, TcpStream},
28+
# net::{TcpListener, TcpStream, ToSocketAddrs},
2929
# prelude::*,
3030
# task,
3131
# };
@@ -35,7 +35,6 @@ Let's add waiting to the server:
3535
# };
3636
# use std::{
3737
# collections::hash_map::{HashMap, Entry},
38-
# net::ToSocketAddrs,
3938
# sync::Arc,
4039
# };
4140
#
@@ -160,7 +159,7 @@ And to the broker:
160159
# extern crate futures;
161160
# use async_std::{
162161
# io::{self, BufReader},
163-
# net::{TcpListener, TcpStream},
162+
# net::{TcpListener, TcpStream, ToSocketAddrs},
164163
# prelude::*,
165164
# task,
166165
# };
@@ -170,7 +169,6 @@ And to the broker:
170169
# };
171170
# use std::{
172171
# collections::hash_map::{HashMap, Entry},
173-
# net::ToSocketAddrs,
174172
# sync::Arc,
175173
# };
176174
#

docs/src/tutorial/handling_disconnection.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,12 @@ The final code looks like this:
121121
# extern crate futures;
122122
use async_std::{
123123
io::{BufReader, BufRead, Write},
124-
net::{TcpListener, TcpStream},
124+
net::{TcpListener, TcpStream, ToSocketAddrs},
125125
task,
126126
};
127127
use futures::{channel::mpsc, future::Future, select, FutureExt, SinkExt, StreamExt};
128128
use std::{
129129
collections::hash_map::{Entry, HashMap},
130-
net::ToSocketAddrs,
131130
sync::Arc,
132131
};
133132

docs/src/tutorial/implementing_a_client.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ With async, we can just use the `select!` macro.
1919
# extern crate futures;
2020
use async_std::{
2121
io::{stdin, BufRead, BufReader, Write},
22-
net::TcpStream,
22+
net::{TcpStream, ToSocketAddrs},
2323
task,
2424
};
2525
use futures::{select, FutureExt, StreamExt};
26-
use std::net::ToSocketAddrs;
2726
2827
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
2928

docs/src/tutorial/receiving_messages.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ We need to:
1111
# extern crate async_std;
1212
# use async_std::{
1313
# io::{BufRead, BufReader},
14-
# net::{TcpListener, TcpStream},
14+
# net::{TcpListener, TcpStream. ToSocketAddrs},
1515
# prelude::Stream,
1616
# task,
1717
# };
18-
# use std::net::ToSocketAddrs;
1918
#
2019
# type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
2120
#
@@ -77,11 +76,10 @@ We can "fix" it by waiting for the task to be joined, like this:
7776
# extern crate async_std;
7877
# use async_std::{
7978
# io::{BufRead, BufReader},
80-
# net::{TcpListener, TcpStream},
79+
# net::{TcpListener, TcpStream, ToSocketAddrs},
8180
# prelude::Stream,
8281
# task,
8382
# };
84-
# use std::net::ToSocketAddrs;
8583
#
8684
# type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
8785
#

0 commit comments

Comments
 (0)