From 7faeea5acc3c24493b97306f0238712bf7e0b4e9 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Mon, 21 Nov 2022 15:19:11 -0800 Subject: [PATCH] Fix clippy/deprecation warnings --- postgres-protocol/src/authentication/mod.rs | 2 +- postgres-types/src/chrono_04.rs | 8 ++++---- postgres-types/src/geo_types_07.rs | 4 ++-- postgres-types/src/lib.rs | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/postgres-protocol/src/authentication/mod.rs b/postgres-protocol/src/authentication/mod.rs index 9cfd6034..71afa4b9 100644 --- a/postgres-protocol/src/authentication/mod.rs +++ b/postgres-protocol/src/authentication/mod.rs @@ -15,7 +15,7 @@ pub fn md5_hash(username: &[u8], password: &[u8], salt: [u8; 4]) -> String { md5.update(username); let output = md5.finalize_reset(); md5.update(format!("{:x}", output)); - md5.update(&salt); + md5.update(salt); format!("md5{:x}", md5.finalize()) } diff --git a/postgres-types/src/chrono_04.rs b/postgres-types/src/chrono_04.rs index fcd25e6d..180ee376 100644 --- a/postgres-types/src/chrono_04.rs +++ b/postgres-types/src/chrono_04.rs @@ -6,7 +6,7 @@ use std::error::Error; use crate::{FromSql, IsNull, ToSql, Type}; fn base() -> NaiveDateTime { - NaiveDate::from_ymd(2000, 1, 1).and_hms(0, 0, 0) + NaiveDate::from_ymd_opt(2000, 1, 1).unwrap().and_hms_opt(0, 0, 0).unwrap() } impl<'a> FromSql<'a> for NaiveDateTime { @@ -84,7 +84,7 @@ impl<'a> FromSql<'a> for DateTime { raw: &[u8], ) -> Result, Box> { let utc = DateTime::::from_sql(type_, raw)?; - Ok(utc.with_timezone(&FixedOffset::east(0))) + Ok(utc.with_timezone(&FixedOffset::east_opt(0).unwrap())) } accepts!(TIMESTAMPTZ); @@ -133,7 +133,7 @@ impl ToSql for NaiveDate { impl<'a> FromSql<'a> for NaiveTime { fn from_sql(_: &Type, raw: &[u8]) -> Result> { let usec = types::time_from_sql(raw)?; - Ok(NaiveTime::from_hms(0, 0, 0) + Duration::microseconds(usec)) + Ok(NaiveTime::from_hms_opt(0, 0, 0).unwrap() + Duration::microseconds(usec)) } accepts!(TIME); @@ -141,7 +141,7 @@ impl<'a> FromSql<'a> for NaiveTime { impl ToSql for NaiveTime { fn to_sql(&self, _: &Type, w: &mut BytesMut) -> Result> { - let delta = self.signed_duration_since(NaiveTime::from_hms(0, 0, 0)); + let delta = self.signed_duration_since(NaiveTime::from_hms_opt(0, 0, 0).unwrap()); let time = match delta.num_microseconds() { Some(time) => time, None => return Err("value too large to transmit".into()), diff --git a/postgres-types/src/geo_types_07.rs b/postgres-types/src/geo_types_07.rs index 7dfb5105..bf7fa560 100644 --- a/postgres-types/src/geo_types_07.rs +++ b/postgres-types/src/geo_types_07.rs @@ -1,6 +1,6 @@ use bytes::BytesMut; use fallible_iterator::FallibleIterator; -use geo_types_0_7::{Coordinate, LineString, Point, Rect}; +use geo_types_0_7::{Coord, LineString, Point, Rect}; use postgres_protocol::types; use std::error::Error; @@ -52,7 +52,7 @@ impl<'a> FromSql<'a> for LineString { let path = types::path_from_sql(raw)?; let points = path .points() - .map(|p| Ok(Coordinate { x: p.x(), y: p.y() })) + .map(|p| Ok(Coord { x: p.x(), y: p.y() })) .collect()?; Ok(LineString(points)) } diff --git a/postgres-types/src/lib.rs b/postgres-types/src/lib.rs index f5d841cd..ca4233f8 100644 --- a/postgres-types/src/lib.rs +++ b/postgres-types/src/lib.rs @@ -938,7 +938,7 @@ impl<'a, T: ToSql> ToSql for &'a [T] { impl<'a> ToSql for &'a [u8] { fn to_sql(&self, _: &Type, w: &mut BytesMut) -> Result> { - types::bytea_to_sql(*self, w); + types::bytea_to_sql(self, w); Ok(IsNull::No) } @@ -1011,10 +1011,10 @@ impl ToSql for Vec { impl<'a> ToSql for &'a str { fn to_sql(&self, ty: &Type, w: &mut BytesMut) -> Result> { match *ty { - ref ty if ty.name() == "ltree" => types::ltree_to_sql(*self, w), - ref ty if ty.name() == "lquery" => types::lquery_to_sql(*self, w), - ref ty if ty.name() == "ltxtquery" => types::ltxtquery_to_sql(*self, w), - _ => types::text_to_sql(*self, w), + ref ty if ty.name() == "ltree" => types::ltree_to_sql(self, w), + ref ty if ty.name() == "lquery" => types::lquery_to_sql(self, w), + ref ty if ty.name() == "ltxtquery" => types::ltxtquery_to_sql(self, w), + _ => types::text_to_sql(self, w), } Ok(IsNull::No) }