Skip to content

Commit 7d2c9d6

Browse files
author
bors-servo
authored
Auto merge of servo#536 - benesch:upgrade-20, r=SimonSapin
Add an upgrade guide for v2.0. Extracted from servo#534, with review feedback addressed. This variant omits the changelogs in an effort to introduce less of a maintenance burden. Fix servo#532. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-url/536) <!-- Reviewable:end -->
2 parents 0e874dd + 0311660 commit 7d2c9d6

File tree

1 file changed

+105
-1
lines changed

1 file changed

+105
-1
lines changed

UPGRADING.md

+105-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,108 @@
1-
# Guide to upgrading from url 0.x to 1.x
1+
# Upgrade guide
2+
3+
This guide contains steps for upgrading crates in this project between major
4+
versions.
5+
6+
## Upgrading from url 1.x to 2.1+
7+
8+
* The minimum supported Rust version is now v1.33.0. Verify that you can bump
9+
your library or application to the same MSRV.
10+
11+
* `Url` no longer implements `std::net::ToSocketAddrs`. You will instead need to
12+
explicitly call `socket_addrs` to convert your `Url` to a type that implements
13+
`ToSocketAddrs`.
14+
15+
Note that v2.0 removed support for `std::net::ToSocketAddrs` with no
16+
replacement; the `socket_addrs` method was not added until v2.1.
17+
18+
Before upgrading:
19+
20+
```rust
21+
let url = Url::parse("http://github.com:80").unwrap();
22+
let stream = TcpStream::connect(url).unwrap();
23+
```
24+
25+
After upgrading:
26+
27+
```rust
28+
let url = Url::parse("http://github.com:80").unwrap();
29+
let addrs = url.socket_addrs(|| None).unwrap();
30+
let stream = TcpStream::connect(addrs).unwrap();
31+
```
32+
33+
Before upgrading:
34+
35+
```rust
36+
let url = Url::parse("socks5://localhost").unwrap();
37+
let stream = TcpStream::connect(url.with_default_port(|url| match url.scheme() {
38+
"socks5" => Ok(1080),
39+
_ => Err(()),
40+
})).unwrap();
41+
```
42+
43+
After upgrading:
44+
45+
```rust
46+
let url = Url::parse("http://github.com:80").unwrap();
47+
let stream = TcpStream::connect(url.socket_addrs(|| match url.scheme() {
48+
"socks5" => Some(1080),
49+
_ => Err(()),
50+
})).unwrap();
51+
```
52+
53+
* `url_serde` is no longer required to use `Url` with Serde 1.x. Remove
54+
references to `url_serde` and enable the `serde` feature instead.
55+
56+
```toml
57+
# Cargo.toml
58+
[dependencies]
59+
url = { version = "2.0", features = ["serde"] }
60+
```
61+
62+
* The `idna` and `percent_export` crates are no longer exported by the `url`
63+
crate. Depend on those crates directly instead. See below for additional
64+
breaking changes in the percent-export package.
65+
66+
Before upgrading:
67+
68+
```rust
69+
use url::percent_encoding::percent_decode;
70+
```
71+
72+
After upgrading:
73+
74+
```rust
75+
use percent_encoding::percent_decode;
76+
```
77+
78+
## Upgrading from percent-encoding 1.x to 2.x
79+
80+
* Prepackaged encoding sets, like `QUERY_ENCODE_SET` and
81+
`PATH_SEGMENT_ENCODE_SET`, are no longer provided. You
82+
will need to read the specifications relevant to your domain and construct
83+
your own encoding sets by using the `percent_encoding::AsciiSet` builder
84+
methods on either of the base encoding sets, `percent_encoding::CONTROLS` or
85+
`percent_encoding::NON_ALPHANUMERIC`.
86+
87+
Before upgrading:
88+
89+
```rust
90+
use percent_encoding::QUERY_ENCODE_SET;
91+
92+
percent_encoding::utf8_percent_encode(value, QUERY_ENCODE_SET);
93+
```
94+
95+
After upgrading:
96+
97+
```rust
98+
/// https://url.spec.whatwg.org/#query-state
99+
const QUERY: &AsciiSet = &CONTROLS.add(b' ').add(b'"').add(b'#').add(b'<').add(b'>');
100+
101+
percent_encoding::utf8_percent_encode(value, QUERY);
102+
```
103+
104+
105+
## Upgrading from url 0.x to 1.x
2106

3107
* The fields of `Url` are now private because the `Url` constructor, parser,
4108
and setters maintain invariants that could be violated if you were to set the fields directly.

0 commit comments

Comments
 (0)