Skip to content

Commit 4f805dd

Browse files
benescho0Ignition0o
andcommitted
Fix typo in UPGRADING.md
Co-Authored-By: Jeremy Lempereur <[email protected]>
1 parent 8287b2c commit 4f805dd

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

UPGRADING.md

+28-20
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ This guide contains steps for upgrading crates in this project between major
44
versions. Only the most common issues are covered here. For full details of
55
changes, see the [changelog](CHANGELOG.md).
66

7-
## Upgrading from url 1.x to 2.x
7+
## Upgrading from url 1.x to 2.1+
88

99
* The minimum supported Rust version is now v1.33.0. Verify that you can bump
1010
your library or application to the same MSRV.
1111

1212
* `Url` no longer implements `std::net::ToSocketAddrs`. You will instead need to
13-
explicitly convert your `Url` to a type that implements `ToSocketAddrs`.
13+
explicitly call `socket_addrs` to convert your `Url` to a type that implements
14+
`ToSocketAddrs`.
15+
16+
Note that v2.0 removed support for `std::net::ToSocketAddrs` with no
17+
replacement; the `socket_addrs` method was not added until v2.1.
1418

1519
Before upgrading:
1620

@@ -23,26 +27,30 @@ changes, see the [changelog](CHANGELOG.md).
2327

2428
```rust
2529
let url = Url::parse("http://github.com:80").unwrap();
26-
let port = url.port_or_known_default().unwrap();
27-
let addrs;
28-
let addr;
29-
let addrs = match url.host().unwrap() {
30-
url::Host::Domain(domain) => {
31-
addrs = (domain, port).to_socket_addrs().unwrap();
32-
addrs.as_slice()
33-
}
34-
url::Host::Ipv4(ip) => {
35-
addr = (ip, port).into();
36-
std::slice::from_ref(&addr)
37-
}
38-
url::Host::Ipv6(ip) => {
39-
addr = (ip, port).into();
40-
std::slice::from_ref(&addr)
41-
}
42-
};
30+
let addrs = url.socket_addrs(|| None).unwrap();
4331
let stream = TcpStream::connect(addrs).unwrap();
4432
```
4533

34+
Before upgrading:
35+
36+
```rust
37+
let url = Url::parse("socks5://localhost").unwrap();
38+
let stream = TcpStream::connect(url.with_default_port(|url| match url.scheme() {
39+
"socks5" => Ok(1080),
40+
_ => Err(()),
41+
})).unwrap();
42+
```
43+
44+
After upgrading:
45+
46+
```rust
47+
let url = Url::parse("http://github.com:80").unwrap();
48+
let stream = TcpStream::connect(url.socket_addrs(|| match url.scheme() {
49+
"socks5" => Some(1080),
50+
_ => Err(()),
51+
})).unwrap();
52+
```
53+
4654
* `url_serde` is no longer required to use `Url` with Serde 1.x. Remove
4755
references to `url_serde` and enable the `serde` feature instead.
4856

@@ -71,7 +79,7 @@ changes, see the [changelog](CHANGELOG.md).
7179
## Upgrading from percent-encoding 1.x to 2.x
7280

7381
* Prepackaged encoding sets, like `QUERY_ENCODE_SET` and
74-
`PATH_SEGMENT_ENCODE_SET`, are no longer provided. You will need to read You
82+
`PATH_SEGMENT_ENCODE_SET`, are no longer provided. You
7583
will need to read the specifications relevant to your domain and construct
7684
your own encoding sets by using the `percent_encoding::AsciiSet` builder
7785
methods on either of the base encoding sets, `percent_encoding::CONTROLS` or

0 commit comments

Comments
 (0)