From 3d575495e7e0a43cb19edba000c2b438ad2f0e09 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Fri, 16 Apr 2021 11:49:47 -0700 Subject: [PATCH] style: rustfmt --- sqlx-core/src/null.rs | 3 ++- sqlx-mysql/src/connection/command.rs | 24 ++++--------------- sqlx-mysql/src/error/client.rs | 3 ++- .../src/protocol/auth_plugin/caching_sha2.rs | 9 +++---- sqlx-mysql/src/protocol/auth_plugin/dialog.rs | 3 ++- sqlx-mysql/src/protocol/auth_plugin/rsa.rs | 7 +++--- sqlx-mysql/src/protocol/auth_plugin/sha256.rs | 7 +++--- sqlx-mysql/src/protocol/execute.rs | 2 +- sqlx-mysql/src/types/null.rs | 3 ++- sqlx-postgres/src/error/database.rs | 3 ++- sqlx-postgres/src/protocol/backend/notice.rs | 17 ++++++++----- sqlx-postgres/src/stream.rs | 6 ++--- 12 files changed, 41 insertions(+), 46 deletions(-) diff --git a/sqlx-core/src/null.rs b/sqlx-core/src/null.rs index 59614609..eb377cb2 100644 --- a/sqlx-core/src/null.rs +++ b/sqlx-core/src/null.rs @@ -1,6 +1,7 @@ +use std::ops::Not; + use crate::database::{HasOutput, HasRawValue}; use crate::{decode, encode, Database, Decode, Encode, RawValue, Type}; -use std::ops::Not; #[derive(Debug)] pub struct Null; diff --git a/sqlx-mysql/src/connection/command.rs b/sqlx-mysql/src/connection/command.rs index 4f185047..df12891e 100644 --- a/sqlx-mysql/src/connection/command.rs +++ b/sqlx-mysql/src/connection/command.rs @@ -102,11 +102,7 @@ impl Deref for CommandGuard<'_, QueryCommand> { fn deref(&self) -> &Self::Target { debug_assert!(!self.ended); - if let Command::Query(cmd) = &self.queue.0[self.index] { - cmd - } else { - unreachable!() - } + if let Command::Query(cmd) = &self.queue.0[self.index] { cmd } else { unreachable!() } } } @@ -114,11 +110,7 @@ impl DerefMut for CommandGuard<'_, QueryCommand> { fn deref_mut(&mut self) -> &mut Self::Target { debug_assert!(!self.ended); - if let Command::Query(cmd) = &mut self.queue.0[self.index] { - cmd - } else { - unreachable!() - } + if let Command::Query(cmd) = &mut self.queue.0[self.index] { cmd } else { unreachable!() } } } @@ -147,11 +139,7 @@ impl Deref for CommandGuard<'_, PrepareCommand> { fn deref(&self) -> &Self::Target { debug_assert!(!self.ended); - if let Command::Prepare(cmd) = &self.queue.0[self.index] { - cmd - } else { - unreachable!() - } + if let Command::Prepare(cmd) = &self.queue.0[self.index] { cmd } else { unreachable!() } } } @@ -159,10 +147,6 @@ impl DerefMut for CommandGuard<'_, PrepareCommand> { fn deref_mut(&mut self) -> &mut Self::Target { debug_assert!(!self.ended); - if let Command::Prepare(cmd) = &mut self.queue.0[self.index] { - cmd - } else { - unreachable!() - } + if let Command::Prepare(cmd) = &mut self.queue.0[self.index] { cmd } else { unreachable!() } } } diff --git a/sqlx-mysql/src/error/client.rs b/sqlx-mysql/src/error/client.rs index 076c4325..017725b8 100644 --- a/sqlx-mysql/src/error/client.rs +++ b/sqlx-mysql/src/error/client.rs @@ -1,9 +1,10 @@ use std::error::Error as StdError; use std::fmt::{self, Display, Formatter}; -use crate::protocol::AuthPlugin; use sqlx_core::{ClientError, Error}; +use crate::protocol::AuthPlugin; + #[derive(Debug)] #[non_exhaustive] pub enum MySqlClientError { diff --git a/sqlx-mysql/src/protocol/auth_plugin/caching_sha2.rs b/sqlx-mysql/src/protocol/auth_plugin/caching_sha2.rs index 420c4247..f8d82b60 100644 --- a/sqlx-mysql/src/protocol/auth_plugin/caching_sha2.rs +++ b/sqlx-mysql/src/protocol/auth_plugin/caching_sha2.rs @@ -1,12 +1,13 @@ -use super::rsa::encrypt as rsa_encrypt; -use super::xor_eq; -use crate::protocol::AuthPlugin; -use crate::MySqlClientError; use bytes::buf::Chain; use bytes::Bytes; use sha2::{Digest, Sha256}; use sqlx_core::Result; +use super::rsa::encrypt as rsa_encrypt; +use super::xor_eq; +use crate::protocol::AuthPlugin; +use crate::MySqlClientError; + /// Implements SHA-256 authentication but uses caching on the server-side for better performance. /// After the first authentication, a fast path is used that doesn't involve the RSA key exchange. /// diff --git a/sqlx-mysql/src/protocol/auth_plugin/dialog.rs b/sqlx-mysql/src/protocol/auth_plugin/dialog.rs index 3a6cbcee..afef7c7c 100644 --- a/sqlx-mysql/src/protocol/auth_plugin/dialog.rs +++ b/sqlx-mysql/src/protocol/auth_plugin/dialog.rs @@ -1,8 +1,9 @@ -use crate::MySqlClientError; use bytes::buf::Chain; use bytes::Bytes; use sqlx_core::Result; +use crate::MySqlClientError; + /// Dialog authentication implementation /// /// https://mariadb.com/kb/en/authentication-plugin-pam/#dialog diff --git a/sqlx-mysql/src/protocol/auth_plugin/rsa.rs b/sqlx-mysql/src/protocol/auth_plugin/rsa.rs index 329a0c98..2c4d29cb 100644 --- a/sqlx-mysql/src/protocol/auth_plugin/rsa.rs +++ b/sqlx-mysql/src/protocol/auth_plugin/rsa.rs @@ -1,13 +1,14 @@ use std::str::from_utf8; -use crate::protocol::auth_plugin::xor_eq; -use crate::protocol::AuthPlugin; -use crate::MySqlClientError; use bytes::buf::Chain; use bytes::Bytes; use rsa::{PaddingScheme, PublicKey, RSAPublicKey}; use sqlx_core::Result; +use crate::protocol::auth_plugin::xor_eq; +use crate::protocol::AuthPlugin; +use crate::MySqlClientError; + pub(crate) fn encrypt( plugin: &impl AuthPlugin, key: &[u8], diff --git a/sqlx-mysql/src/protocol/auth_plugin/sha256.rs b/sqlx-mysql/src/protocol/auth_plugin/sha256.rs index 418a4fd8..cb9b50e1 100644 --- a/sqlx-mysql/src/protocol/auth_plugin/sha256.rs +++ b/sqlx-mysql/src/protocol/auth_plugin/sha256.rs @@ -1,10 +1,11 @@ -use super::rsa::encrypt as rsa_encrypt; -use crate::protocol::AuthPlugin; -use crate::MySqlClientError; use bytes::buf::Chain; use bytes::Bytes; use sqlx_core::Result; +use super::rsa::encrypt as rsa_encrypt; +use crate::protocol::AuthPlugin; +use crate::MySqlClientError; + /// Implements SHA-256 authentication. /// /// Each time we connect we have to do an RSA key exchange. diff --git a/sqlx-mysql/src/protocol/execute.rs b/sqlx-mysql/src/protocol/execute.rs index 1ce0f9b0..0f74fe72 100644 --- a/sqlx-mysql/src/protocol/execute.rs +++ b/sqlx-mysql/src/protocol/execute.rs @@ -1,11 +1,11 @@ use std::fmt::{self, Debug, Formatter}; +use sqlx_core::encode::IsNull; use sqlx_core::io::Serialize; use sqlx_core::{Arguments, Result}; use super::Command; use crate::{MySql, MySqlOutput, MySqlTypeId, MySqlTypeInfo}; -use sqlx_core::encode::IsNull; // https://dev.mysql.com/doc/dev/mysql-server/8.0.12/mysql__com_8h.html#a3e5e9e744ff6f7b989a604fd669977da const NO_CURSOR: u8 = 0; diff --git a/sqlx-mysql/src/types/null.rs b/sqlx-mysql/src/types/null.rs index 88281eb6..1d84a62c 100644 --- a/sqlx-mysql/src/types/null.rs +++ b/sqlx-mysql/src/types/null.rs @@ -1,7 +1,8 @@ -use crate::{MySql, MySqlOutput, MySqlRawValue, MySqlTypeId, MySqlTypeInfo}; use sqlx_core::database::{HasOutput, HasRawValue}; use sqlx_core::{decode, encode, Database, Decode, Encode, Null, Type}; +use crate::{MySql, MySqlOutput, MySqlRawValue, MySqlTypeId, MySqlTypeInfo}; + impl Type for Null { fn type_id() -> MySqlTypeId where diff --git a/sqlx-postgres/src/error/database.rs b/sqlx-postgres/src/error/database.rs index 7e7b7a7a..33518ba7 100644 --- a/sqlx-postgres/src/error/database.rs +++ b/sqlx-postgres/src/error/database.rs @@ -1,7 +1,8 @@ -use sqlx_core::{DatabaseError, Error}; use std::error::Error as StdError; use std::fmt::{self, Display, Formatter}; +use sqlx_core::{DatabaseError, Error}; + use crate::PgNotice; /// An error returned from the PostgreSQL database. diff --git a/sqlx-postgres/src/protocol/backend/notice.rs b/sqlx-postgres/src/protocol/backend/notice.rs index cf8f4623..f469b78c 100644 --- a/sqlx-postgres/src/protocol/backend/notice.rs +++ b/sqlx-postgres/src/protocol/backend/notice.rs @@ -1,14 +1,16 @@ -use crate::PgClientError; -use bytes::{Buf, Bytes}; -use bytestring::ByteString; -use memchr::memchr; -use sqlx_core::io::Deserialize; use std::convert::TryFrom; use std::fmt; use std::fmt::{Debug, Display, Formatter}; use std::num::NonZeroU8; use std::str::{from_utf8, FromStr}; +use bytes::{Buf, Bytes}; +use bytestring::ByteString; +use memchr::memchr; +use sqlx_core::io::Deserialize; + +use crate::PgClientError; + #[derive(Debug, Copy, Clone, PartialEq)] #[repr(u8)] pub enum PgNoticeSeverity { @@ -374,7 +376,10 @@ mod tests { assert!(notice.severity.is_error()); assert_eq!(notice.severity, PgNoticeSeverity::Fatal); - assert_eq!(notice.message, "failed to parse error received from postgres, likely invalid authentication, confirm connection information and check database logs"); + assert_eq!( + notice.message, + "failed to parse error received from postgres, likely invalid authentication, confirm connection information and check database logs" + ); assert_eq!(notice.code, "28P01"); Ok(()) diff --git a/sqlx-postgres/src/stream.rs b/sqlx-postgres/src/stream.rs index f0716a55..172d43b4 100644 --- a/sqlx-postgres/src/stream.rs +++ b/sqlx-postgres/src/stream.rs @@ -7,11 +7,9 @@ use sqlx_core::io::{BufStream, Deserialize, Serialize, Stream}; use sqlx_core::net::Stream as NetStream; use sqlx_core::{Result, Runtime}; +use crate::protocol::backend::{BackendMessage, BackendMessageType}; use crate::protocol::frontend::Terminate; -use crate::{ - protocol::backend::{BackendMessage, BackendMessageType}, - PgDatabaseError, PgNotice, -}; +use crate::{PgDatabaseError, PgNotice}; /// Reads and writes messages to and from the PostgreSQL database server. ///