Skip to content

Commit 42358a3

Browse files
committed
fix: prefer ipnetwork to ipnet for compatibility
1 parent 401ece5 commit 42358a3

File tree

7 files changed

+19
-19
lines changed

7 files changed

+19
-19
lines changed

sqlx-postgres/src/type_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl PgTypeInfo {
256256
]
257257
.contains(self)
258258
{
259-
Some("ipnet")
259+
Some("ipnetwork")
260260
} else if [PgTypeInfo::MACADDR].contains(self) {
261261
Some("mac_address")
262262
} else if [PgTypeInfo::NUMERIC, PgTypeInfo::NUMERIC_ARRAY].contains(self) {

sqlx-postgres/src/types/ipnet/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Prefer `ipnetwork` over `ipnet` because it was implemented first (want to avoid breaking change).
2+
#[cfg(not(feature = "ipnetwork"))]
13
mod ipaddr;
24

35
// Parent module is named after the `ipnet` crate, this is named after the `IpNet` type.

sqlx-postgres/src/types/ipnetwork/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Prefer `ipnet` over `ipnetwork`, as it is more featureful and more widely used.
2-
#[cfg(not(feature = "ipnet"))]
31
mod ipaddr;
42

53
// Parent module is named after the `ipnetwork` crate, this is named after the `IpNetwork` type.

sqlx-postgres/src/types/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,28 +81,28 @@
8181
//! |---------------------------------------|------------------------------------------------------|
8282
//! | `uuid::Uuid` | UUID |
8383
//!
84-
//! ### [`ipnet`](https://crates.io/crates/ipnet)
84+
//! ### [`ipnetwork`](https://crates.io/crates/ipnetwork)
8585
//!
86-
//! Requires the `ipnet` Cargo feature flag (takes precedence over `ipnetwork` if both are used).
86+
//! Requires the `ipnetwork` Cargo feature flag (takes precedence over `ipnet` if both are used).
8787
//!
8888
//! | Rust type | Postgres type(s) |
8989
//! |---------------------------------------|------------------------------------------------------|
90-
//! | `ipnet::IpNet` | INET, CIDR |
90+
//! | `ipnetwork::IpNetwork` | INET, CIDR |
9191
//! | `std::net::IpAddr` | INET, CIDR |
9292
//!
9393
//! Note that because `IpAddr` does not support network prefixes, it is an error to attempt to decode
9494
//! an `IpAddr` from a `INET` or `CIDR` value with a network prefix smaller than the address' full width:
9595
//! `/32` for IPv4 addresses and `/128` for IPv6 addresses.
9696
//!
97-
//! `IpNet` does not have this limitation.
97+
//! `IpNetwork` does not have this limitation.
9898
//!
99-
//! ### [`ipnetwork`](https://crates.io/crates/ipnetwork)
99+
//! ### [`ipnet`](https://crates.io/crates/ipnet)
100100
//!
101-
//! Requires the `ipnetwork` Cargo feature flag.
101+
//! Requires the `ipnet` Cargo feature flag.
102102
//!
103103
//! | Rust type | Postgres type(s) |
104104
//! |---------------------------------------|------------------------------------------------------|
105-
//! | `ipnetwork::IpNetwork` | INET, CIDR |
105+
//! | `ipnet::IpNet` | INET, CIDR |
106106
//! | `std::net::IpAddr` | INET, CIDR |
107107
//!
108108
//! The same `IpAddr` limitation for smaller network prefixes applies as with `ipnet`.

tests/ui-tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn ui_tests() {
1818
}
1919

2020
if cfg!(not(feature = "ipnet")) && cfg!(not(feature = "ipnetwork")) {
21-
t.compile_fail("tests/ui/postgres/gated/ipnet.rs");
21+
t.compile_fail("tests/ui/postgres/gated/ipnetwork.rs");
2222
}
2323
}
2424

tests/ui/postgres/gated/ipnet.stderr renamed to tests/ui/postgres/gated/ipnetwork.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
error: optional sqlx feature `ipnet` required for type INET of column #1 ("inet")
2-
--> $DIR/ipnet.rs:2:13
1+
error: optional sqlx feature `ipnetwork` required for type INET of column #1 ("inet")
2+
--> $DIR/ipnetwork.rs:2:13
33
|
44
2 | let _ = sqlx::query!("select '127.0.0.1'::inet");
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
88

9-
error: optional sqlx feature `ipnet` required for type CIDR of column #1 ("cidr")
10-
--> $DIR/ipnet.rs:4:13
9+
error: optional sqlx feature `ipnetwork` required for type CIDR of column #1 ("cidr")
10+
--> $DIR/ipnetwork.rs:4:13
1111
|
1212
4 | let _ = sqlx::query!("select '2001:4f8:3:ba::/64'::cidr");
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414
|
1515
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1616

17-
error: optional sqlx feature `ipnet` required for type INET of param #1
18-
--> $DIR/ipnet.rs:6:13
17+
error: optional sqlx feature `ipnetwork` required for type INET of param #1
18+
--> $DIR/ipnetwork.rs:6:13
1919
|
2020
6 | let _ = sqlx::query!("select $1::inet", ());
2121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2222
|
2323
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
2424

25-
error: optional sqlx feature `ipnet` required for type CIDR of param #1
26-
--> $DIR/ipnet.rs:8:13
25+
error: optional sqlx feature `ipnetwork` required for type CIDR of param #1
26+
--> $DIR/ipnetwork.rs:8:13
2727
|
2828
8 | let _ = sqlx::query!("select $1::cidr", ());
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)