|
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. Only the most common issues are covered here. For full details of |
| 5 | +changes, see the [changelog](CHANGELOG.md). |
| 6 | + |
| 7 | +## Upgrading from url 1.x to 2.x |
| 8 | + |
| 9 | +* The minimum supported Rust version is now v1.33.0. Verify that you can bump |
| 10 | + your library or application to the same MSRV. |
| 11 | + |
| 12 | +* `Url` no longer implements `std::net::ToSocketAddrs`. You will instead need to |
| 13 | + explicitly convert your `Url` to a type that implements `ToSocketAddrs`. |
| 14 | + |
| 15 | + Before upgrading: |
| 16 | + |
| 17 | + ```rust |
| 18 | + let url = Url::parse("http://github.com:80").unwrap(); |
| 19 | + let stream = TcpStream::connect(url).unwrap(); |
| 20 | + ``` |
| 21 | + |
| 22 | + After upgrading: |
| 23 | + |
| 24 | + ```rust |
| 25 | + 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 | + }; |
| 43 | + let stream = TcpStream::connect(addrs).unwrap(); |
| 44 | + ``` |
| 45 | + |
| 46 | +* `url_serde` is no longer required to use `Url` with Serde 1.x. Remove |
| 47 | + references to `url_serde` and enable the `serde` feature instead. |
| 48 | + |
| 49 | + ```toml |
| 50 | + # Cargo.toml |
| 51 | + [dependencies] |
| 52 | + url = { version = "2.0", features = ["serde"] } |
| 53 | + ``` |
| 54 | + |
| 55 | +* The `idna` and `percent_export` crates are no longer exported by the `url` |
| 56 | + crate. Depend on those crates directly instead. See below for additional |
| 57 | + breaking changes in the percent-export package. |
| 58 | + |
| 59 | + Before upgrading: |
| 60 | + |
| 61 | + ```rust |
| 62 | + use url::percent_encoding::percent_decode; |
| 63 | + ``` |
| 64 | + |
| 65 | + After upgrading: |
| 66 | + |
| 67 | + ```rust |
| 68 | + use percent_encoding::percent_decode; |
| 69 | + ``` |
| 70 | + |
| 71 | +## Upgrading from percent-encoding 1.x to 2.x |
| 72 | + |
| 73 | +* Prepackaged encoding sets, like `QUERY_ENCODE_SET` and |
| 74 | + `PATH_SEGMENT_ENCODE_SET`, are no longer provided. You will need to read You |
| 75 | + will need to read the specifications relevant to your domain and construct |
| 76 | + your own encoding sets by using the `percent_encoding::AsciiSet` builder |
| 77 | + methods on either of the base encoding sets, `percent_encoding::CONTROLS` or |
| 78 | + `percent_encoding::NON_ALPHANUMERIC`. |
| 79 | + |
| 80 | + Before upgrading: |
| 81 | + |
| 82 | + ```rust |
| 83 | + use percent_encoding::PATH_SEGMENT_ENCODE_SET; |
| 84 | + |
| 85 | + percent_encoding::utf8_percent_encode(value, PATH_SEGMENT_ENCODE_SET); |
| 86 | + ``` |
| 87 | + |
| 88 | + After upgrading: |
| 89 | + |
| 90 | + ```rust |
| 91 | + /// https://url.spec.whatwg.org/#fragment-percent-encode-set |
| 92 | + const FRAGMENT_ENCODE_SET: &AsciiSet = &percent_encoding::CONTROLS |
| 93 | + .add(b' ').add(b'"').add(b'<').add(b'>').add(b'`'); |
| 94 | + |
| 95 | + /// https://url.spec.whatwg.org/#path-percent-encode-set |
| 96 | + const PATH_ENCODE_SET: &AsciiSet = &FRAGMENT_ENCODE_SET |
| 97 | + .add(b'#').add(b'?').add(b'{').add(b'}'); |
| 98 | + |
| 99 | + const PATH_SEGMENT_ENCODE_SET: &AsciiSet = &PATH_ENCODE_SET.add(b'/').add(b'%'); |
| 100 | + |
| 101 | + percent_encoding::utf8_percent_encode(value, PATH_SEGMENT_ENCODE_SET); |
| 102 | + ``` |
| 103 | + |
| 104 | + You can use the [private encoding sets in the URL parser][encoding-sets] as |
| 105 | + a basis. |
| 106 | + |
| 107 | + [encoding-sets]: https://github.com/servo/rust-url/blob/f491cb442edab75be54ff5961af6458a474f1f9a/src/parser.rs#L18-L45 |
| 108 | + |
| 109 | + |
| 110 | +## Upgrading from url 0.x to 1.x |
2 | 111 |
|
3 | 112 | * The fields of `Url` are now private because the `Url` constructor, parser,
|
4 | 113 | and setters maintain invariants that could be violated if you were to set the fields directly.
|
|
0 commit comments