Change error handling in cidr
FromSql
implementations
This commit is contained in:
parent
dd7bc073f7
commit
27039f6c3a
@ -8,8 +8,7 @@ use crate::{FromSql, IsNull, ToSql, Type};
|
||||
impl<'a> FromSql<'a> for IpCidr {
|
||||
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
|
||||
let inet = types::inet_from_sql(raw)?;
|
||||
Ok(IpCidr::new(inet.addr(), inet.netmask())
|
||||
.expect("postgres cidr type has zeroed host portion"))
|
||||
Ok(IpCidr::new(inet.addr(), inet.netmask())?)
|
||||
}
|
||||
|
||||
accepts!(CIDR);
|
||||
@ -28,8 +27,7 @@ impl ToSql for IpCidr {
|
||||
impl<'a> FromSql<'a> for IpInet {
|
||||
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
|
||||
let inet = types::inet_from_sql(raw)?;
|
||||
Ok(IpInet::new(inet.addr(), inet.netmask())
|
||||
.expect("postgres enforces maximum length of netmask"))
|
||||
Ok(IpInet::new(inet.addr(), inet.netmask())?)
|
||||
}
|
||||
|
||||
accepts!(INET);
|
||||
|
Loading…
Reference in New Issue
Block a user