From 27039f6c3a9f05a41b657f1db5489d055363e2a8 Mon Sep 17 00:00:00 2001 From: Tim Anderson Date: Thu, 17 Mar 2022 09:31:13 +1000 Subject: [PATCH] Change error handling in `cidr` `FromSql` implementations --- postgres-types/src/cidr_02.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/postgres-types/src/cidr_02.rs b/postgres-types/src/cidr_02.rs index d4e4965c..2de952c3 100644 --- a/postgres-types/src/cidr_02.rs +++ b/postgres-types/src/cidr_02.rs @@ -8,8 +8,7 @@ use crate::{FromSql, IsNull, ToSql, Type}; impl<'a> FromSql<'a> for IpCidr { fn from_sql(_: &Type, raw: &[u8]) -> Result> { 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> { 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);