-
-
Notifications
You must be signed in to change notification settings - Fork 461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for std::net::{Ipv4Addr, Ipv6Addr, IpAddr} <-> INET #161
Comments
Postgres stores a netmask in addition to the IP address, which is why these implementations don't exist already. |
Indeed, that is a bit of a troublesome mismatch. What I'm doing is: always writing 32 bits / 128 bits in if bits != 32 {
let err: Box<error::Error + Sync + Send> = "INET must have all 32 bits for Ipv4Addr".into();
return Err(Error::Conversion(err));
} in Do you think that is workable? This should at least support the use case where one does not store any netmasks other than the default /32 or /128. |
I would prefer that the implementations in this library be "lossless" in general. |
I take your point. I guess I might want to make a new crate with types that wrap |
I just figured out that there is a way to insert let ipv4_s = format!("{}", Ipv4Addr::new(127, 0, 0, 1));
let ipv6_s = format!("{}", Ipv6Addr::new(1, 2, 3, 4, 5, 6, 7, 8));
conn.execute("INSERT INTO sessions (last_seen_ipv4, last_seen_ipv6)
VALUES (cast($1::text as inet), cast($2::text as inet))", &[&ipv4_s, &ipv6_s]).unwrap(); |
@ivan note that you can use |
Thanks! That does look a lot better. |
@sfackler |
Would you take a PR that does this? (I am working on one.)
The text was updated successfully, but these errors were encountered: