Skip to content

Commit

Permalink
Remove unnecessary deref vol. 2
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubOnderka committed Jul 11, 2021
1 parent 17aa574 commit c4845a3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/diesel_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ impl FromSql<Cidr, Pg> for IpNetwork {

impl ToSql<Cidr, Pg> for Ipv4Network {
fn to_sql<W: Write>(&self, out: &mut Output<W, Pg>) -> serialize::Result {
let data = postgres_common::to_sql_ipv4_network(*self);
let data = postgres_common::to_sql_ipv4_network(self);
out.write_all(&data).map(|_| IsNull::No).map_err(Into::into)
}
}

impl ToSql<Cidr, Pg> for Ipv6Network {
fn to_sql<W: Write>(&self, out: &mut Output<W, Pg>) -> serialize::Result {
let data = postgres_common::to_sql_ipv6_network(*self);
let data = postgres_common::to_sql_ipv6_network(self);
out.write_all(&data).map(|_| IsNull::No).map_err(Into::into)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/postgres_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn from_sql_ipv6_network(raw: &[u8]) -> Result<Ipv6Network, Box<dyn Error +
}

#[inline]
pub fn to_sql_ipv4_network(network: Ipv4Network) -> [u8; 8] {
pub fn to_sql_ipv4_network(network: &Ipv4Network) -> [u8; 8] {
let ip_octets = network.network_address().octets();
let mut bytes = [0; 8];
bytes[0] = IPV4_TYPE;
Expand All @@ -64,7 +64,7 @@ pub fn to_sql_ipv4_network(network: Ipv4Network) -> [u8; 8] {
}

#[inline]
pub fn to_sql_ipv6_network(network: Ipv6Network) -> [u8; 20] {
pub fn to_sql_ipv6_network(network: &Ipv6Network) -> [u8; 20] {
let ip_octets = network.network_address().octets();
let mut bytes = [0; 20];
bytes[0] = IPV6_TYPE;
Expand Down
4 changes: 2 additions & 2 deletions src/postgres_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl FromSql for IpNetwork {

impl ToSql for Ipv4Network {
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> PostgresResult<IsNull> {
let bytes = postgres_common::to_sql_ipv4_network(*self);
let bytes = postgres_common::to_sql_ipv4_network(self);
w.extend_from_slice(&bytes);

Ok(IsNull::No)
Expand All @@ -48,7 +48,7 @@ impl ToSql for Ipv4Network {

impl ToSql for Ipv6Network {
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> PostgresResult<IsNull> {
let bytes = postgres_common::to_sql_ipv6_network(*self);
let bytes = postgres_common::to_sql_ipv6_network(self);
w.extend_from_slice(&bytes);

Ok(IsNull::No)
Expand Down
10 changes: 3 additions & 7 deletions src/serde_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ impl Serialize for IpNetwork {
if serializer.is_human_readable() {
serializer.serialize_str(&self.to_string())
} else {
match *self {
IpNetwork::V4(ref a) => {
serializer.serialize_newtype_variant("IpNetwork", 0, "V4", a)
}
IpNetwork::V6(ref a) => {
serializer.serialize_newtype_variant("IpNetwork", 1, "V6", a)
}
match self {
IpNetwork::V4(a) => serializer.serialize_newtype_variant("IpNetwork", 0, "V4", a),
IpNetwork::V6(a) => serializer.serialize_newtype_variant("IpNetwork", 1, "V6", a),
}
}
}
Expand Down

0 comments on commit c4845a3

Please sign in to comment.