Fix clippy/deprecation warnings

This commit is contained in:
Steven Fackler 2022-11-21 15:19:11 -08:00
parent 71668b7f46
commit 7faeea5acc
No known key found for this signature in database
GPG Key ID: 408917B7276A5226
4 changed files with 12 additions and 12 deletions

View File

@ -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())
}

View File

@ -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<FixedOffset> {
raw: &[u8],
) -> Result<DateTime<FixedOffset>, Box<dyn Error + Sync + Send>> {
let utc = DateTime::<Utc>::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<NaiveTime, Box<dyn Error + Sync + Send>> {
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<IsNull, Box<dyn Error + Sync + Send>> {
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()),

View File

@ -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<f64> {
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))
}

View File

@ -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<IsNull, Box<dyn Error + Sync + Send>> {
types::bytea_to_sql(*self, w);
types::bytea_to_sql(self, w);
Ok(IsNull::No)
}
@ -1011,10 +1011,10 @@ impl ToSql for Vec<u8> {
impl<'a> ToSql for &'a str {
fn to_sql(&self, ty: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
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)
}