You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CREATETABLEsensor_logs (
id SERIALPRIMARY KEY,
host_name VARCHAR(128) NOT NULL,
ip_address INETNOT NULL,
collected TIMESTAMPNOT NULL,
extra JSONB
);
let result = sqlx::query!(r#" INSERT INTO sensor_logs (host_name, ip_address, collected, extra) VALUES ($1, $2, $3, $4) RETURNING id "#,
sensor_log_row.host_name,IpAddr::V4("192.168.1.2".parse().unwrap()),// here
sensor_log_row.collected,
extra_json
).fetch_one(self.txn().as_mut()).await?;
error[E0308]: mismatched types
--> crates/libs/ds-pgsql/src/repository_impl.rs:81:13
|
81 | IpAddr::V4("192.168.1.2".parse().unwrap()),
| ^^^^^^
| |
| expected `IpNetwork`, found `IpAddr`
| expected due to the type of this binding
|
help: call `Into::into` on this expression to convert `std::net::IpAddr` into `sqlx::types::ipnetwork::IpNetwork`
|
81 | IpAddr.into()::V4("192.168.1.2".parse().unwrap()),
| +++++++
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I have bound an IpAddr type to a column of type INET(postgres) as shown below, but sqlx is expecting an IpNetwork type.
The official documentation states that the std::net::IpAddr type and INET type are compatible based on the ipnet features flag.
https://docs.rs/sqlx/latest/sqlx/postgres/types/index.html#ipnet
Am I using it wrong somehow?
Beta Was this translation helpful? Give feedback.
All reactions