Fix: address Clippy warnings

This commit is contained in:
Basti Ortiz 2022-08-15 00:12:18 +08:00
parent a0f028a008
commit 5f3e7aecad
No known key found for this signature in database
GPG Key ID: 1402D5CB17F48E1B
4 changed files with 13 additions and 11 deletions

View File

@ -73,6 +73,8 @@ use tokio_postgres::tls::{ChannelBinding, TlsConnect};
#[cfg(test)] #[cfg(test)]
mod test; mod test;
type ConfigCallback = dyn Fn(&mut ConnectConfiguration, &str) -> Result<(), ErrorStack> + Sync + Send;
/// A `MakeTlsConnect` implementation using the `openssl` crate. /// A `MakeTlsConnect` implementation using the `openssl` crate.
/// ///
/// Requires the `runtime` Cargo feature (enabled by default). /// Requires the `runtime` Cargo feature (enabled by default).
@ -80,7 +82,7 @@ mod test;
#[derive(Clone)] #[derive(Clone)]
pub struct MakeTlsConnector { pub struct MakeTlsConnector {
connector: SslConnector, connector: SslConnector,
config: Arc<dyn Fn(&mut ConnectConfiguration, &str) -> Result<(), ErrorStack> + Sync + Send>, config: Arc<ConfigCallback>,
} }
#[cfg(feature = "runtime")] #[cfg(feature = "runtime")]

View File

@ -6,7 +6,7 @@ use std::{i32, i64};
use crate::{FromSql, IsNull, ToSql, Type}; use crate::{FromSql, IsNull, ToSql, Type};
/// A wrapper that can be used to represent infinity with `Type::Date` types. /// A wrapper that can be used to represent infinity with `Type::Date` types.
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Date<T> { pub enum Date<T> {
/// Represents `infinity`, a date that is later than all other dates. /// Represents `infinity`, a date that is later than all other dates.
PosInfinity, PosInfinity,
@ -55,7 +55,7 @@ impl<T: ToSql> ToSql for Date<T> {
/// A wrapper that can be used to represent infinity with `Type::Timestamp` and `Type::Timestamptz` /// A wrapper that can be used to represent infinity with `Type::Timestamp` and `Type::Timestamptz`
/// types. /// types.
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Timestamp<T> { pub enum Timestamp<T> {
/// Represents `infinity`, a timestamp that is later than all other timestamps. /// Represents `infinity`, a timestamp that is later than all other timestamps.
PosInfinity, PosInfinity,

View File

@ -23,7 +23,7 @@ use std::{error, fmt, iter, mem};
use tokio::io::{AsyncRead, AsyncWrite}; use tokio::io::{AsyncRead, AsyncWrite};
/// Properties required of a session. /// Properties required of a session.
#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[non_exhaustive] #[non_exhaustive]
pub enum TargetSessionAttrs { pub enum TargetSessionAttrs {
/// No special properties are required. /// No special properties are required.
@ -33,7 +33,7 @@ pub enum TargetSessionAttrs {
} }
/// TLS configuration. /// TLS configuration.
#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[non_exhaustive] #[non_exhaustive]
pub enum SslMode { pub enum SslMode {
/// Do not use TLS. /// Do not use TLS.
@ -45,7 +45,7 @@ pub enum SslMode {
} }
/// Channel binding configuration. /// Channel binding configuration.
#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[non_exhaustive] #[non_exhaustive]
pub enum ChannelBinding { pub enum ChannelBinding {
/// Do not use channel binding. /// Do not use channel binding.
@ -57,7 +57,7 @@ pub enum ChannelBinding {
} }
/// A host specification. /// A host specification.
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub enum Host { pub enum Host {
/// A TCP hostname. /// A TCP hostname.
Tcp(String), Tcp(String),
@ -144,7 +144,7 @@ pub enum Host {
/// ```not_rust /// ```not_rust
/// postgresql:///mydb?user=user&host=/var/lib/postgresql /// postgresql:///mydb?user=user&host=/var/lib/postgresql
/// ``` /// ```
#[derive(PartialEq, Clone)] #[derive(Clone, PartialEq, Eq)]
pub struct Config { pub struct Config {
pub(crate) user: Option<String>, pub(crate) user: Option<String>,
pub(crate) password: Option<Vec<u8>>, pub(crate) password: Option<Vec<u8>>,
@ -452,7 +452,7 @@ impl Config {
} }
} }
"target_session_attrs" => { "target_session_attrs" => {
let target_session_attrs = match &*value { let target_session_attrs = match value {
"any" => TargetSessionAttrs::Any, "any" => TargetSessionAttrs::Any,
"read-write" => TargetSessionAttrs::ReadWrite, "read-write" => TargetSessionAttrs::ReadWrite,
_ => { _ => {
@ -900,7 +900,7 @@ impl<'a> UrlParser<'a> {
#[cfg(unix)] #[cfg(unix)]
fn host_param(&mut self, s: &str) -> Result<(), Error> { fn host_param(&mut self, s: &str) -> Result<(), Error> {
let decoded = Cow::from(percent_encoding::percent_decode(s.as_bytes())); let decoded = Cow::from(percent_encoding::percent_decode(s.as_bytes()));
if decoded.get(0) == Some(&b'/') { if decoded.first() == Some(&b'/') {
self.config.host_path(OsStr::from_bytes(&decoded)); self.config.host_path(OsStr::from_bytes(&decoded));
} else { } else {
let decoded = str::from_utf8(&decoded).map_err(|e| Error::config_parse(Box::new(e)))?; let decoded = str::from_utf8(&decoded).map_err(|e| Error::config_parse(Box::new(e)))?;

View File

@ -28,7 +28,7 @@ where
let port = config let port = config
.port .port
.get(i) .get(i)
.or_else(|| config.port.get(0)) .or_else(|| config.port.first())
.copied() .copied()
.unwrap_or(5432); .unwrap_or(5432);