diff --git a/sqlx-core/src/connection.rs b/sqlx-core/src/connection.rs index df2072d0..9311cbae 100644 --- a/sqlx-core/src/connection.rs +++ b/sqlx-core/src/connection.rs @@ -10,7 +10,13 @@ pub struct ConnectOptions<'a> { impl<'a> Default for ConnectOptions<'a> { #[inline] fn default() -> Self { - Self { host: "localhost", port: 5432, user: None, database: None, password: None } + Self { + host: "localhost", + port: 5432, + user: None, + database: None, + password: None, + } } } diff --git a/sqlx-postgres-mock/src/main.rs b/sqlx-postgres-mock/src/main.rs index bab747fe..4f528cd0 100644 --- a/sqlx-postgres-mock/src/main.rs +++ b/sqlx-postgres-mock/src/main.rs @@ -17,8 +17,7 @@ const ESTABLISH: &[u8] = b"\ S\0\0\0#session_authorization\0postgres\0\ S\0\0\0#standard_conforming_strings\0on\0\ S\0\0\0\x11TimeZone\0UTC\0\ - K\0\0\0\x0c\0\0'\xc6\x89\ - R\xc5+\ + K\0\0\0\x0c\0\0'\xc6\x89R\xc5+\ Z\0\0\0\x05I"; #[runtime::main] diff --git a/sqlx-postgres-protocol/benches/decode.rs b/sqlx-postgres-protocol/benches/decode.rs index e39bd279..1988ed2f 100644 --- a/sqlx-postgres-protocol/benches/decode.rs +++ b/sqlx-postgres-protocol/benches/decode.rs @@ -3,7 +3,7 @@ extern crate criterion; use bytes::Bytes; use criterion::{black_box, Criterion}; -use sqlx_postgres_protocol::{Decode, ParameterStatus, BackendKeyData, Response}; +use sqlx_postgres_protocol::{BackendKeyData, Decode, ParameterStatus, Response}; fn criterion_benchmark(c: &mut Criterion) { const NOTICE_RESPONSE: &[u8] = b"SNOTICE\0VNOTICE\0C42710\0Mextension \"uuid-ossp\" already exists, skipping\0Fextension.c\0L1656\0RCreateExtension\0\0"; @@ -18,7 +18,8 @@ fn criterion_benchmark(c: &mut Criterion) { c.bench_function("decode BackendKeyData", |b| { b.iter(|| { - let _ = BackendKeyData::decode(black_box(Bytes::from_static(BACKEND_KEY_DATA))).unwrap(); + let _ = + BackendKeyData::decode(black_box(Bytes::from_static(BACKEND_KEY_DATA))).unwrap(); }) }); diff --git a/sqlx-postgres-protocol/src/backend_key_data.rs b/sqlx-postgres-protocol/src/backend_key_data.rs index a98a1ac7..0388e7f5 100644 --- a/sqlx-postgres-protocol/src/backend_key_data.rs +++ b/sqlx-postgres-protocol/src/backend_key_data.rs @@ -27,14 +27,17 @@ impl Decode for BackendKeyData { let process_id = BigEndian::read_u32(&src[..4]); let secret_key = BigEndian::read_u32(&src[4..]); - Ok(Self { process_id, secret_key }) + Ok(Self { + process_id, + secret_key, + }) } } #[cfg(test)] mod tests { - use super::{BackendKeyData}; - use crate::{Decode}; + use super::BackendKeyData; + use crate::Decode; use bytes::Bytes; use std::io; diff --git a/sqlx-postgres-protocol/src/parameter_status.rs b/sqlx-postgres-protocol/src/parameter_status.rs index 07d573c6..973401e4 100644 --- a/sqlx-postgres-protocol/src/parameter_status.rs +++ b/sqlx-postgres-protocol/src/parameter_status.rs @@ -35,8 +35,8 @@ impl Decode for ParameterStatus { #[cfg(test)] mod tests { - use super::{ParameterStatus}; - use crate::{Decode}; + use super::ParameterStatus; + use crate::Decode; use bytes::Bytes; use std::io; diff --git a/sqlx-postgres-protocol/src/password_message.rs b/sqlx-postgres-protocol/src/password_message.rs index 63ef9cfb..ade079f7 100644 --- a/sqlx-postgres-protocol/src/password_message.rs +++ b/sqlx-postgres-protocol/src/password_message.rs @@ -11,7 +11,9 @@ pub struct PasswordMessage { impl PasswordMessage { /// Create a `PasswordMessage` with an unecrypted password. pub fn cleartext(password: &str) -> Self { - Self { password: Bytes::from(password) } + Self { + password: Bytes::from(password), + } } /// Create a `PasswordMessage` by hasing the password, user, and salt together using MD5. @@ -32,7 +34,9 @@ impl PasswordMessage { password.extend_from_slice(b"md5"); password.extend_from_slice(salted.as_bytes()); - Self { password: Bytes::from(password) } + Self { + password: Bytes::from(password), + } } /// The password (encrypted, if requested). diff --git a/sqlx-postgres-protocol/src/ready_for_query.rs b/sqlx-postgres-protocol/src/ready_for_query.rs index 1da1430e..96f8e0c5 100644 --- a/sqlx-postgres-protocol/src/ready_for_query.rs +++ b/sqlx-postgres-protocol/src/ready_for_query.rs @@ -67,7 +67,9 @@ mod tests { #[test] fn it_encodes_ready_for_query() -> io::Result<()> { - let message = ReadyForQuery { status: TransactionStatus::Error }; + let message = ReadyForQuery { + status: TransactionStatus::Error, + }; let mut dst = Vec::with_capacity(message.size_hint()); message.encode(&mut dst)?; diff --git a/sqlx-postgres-protocol/src/response.rs b/sqlx-postgres-protocol/src/response.rs index 569f4979..3a9280dc 100644 --- a/sqlx-postgres-protocol/src/response.rs +++ b/sqlx-postgres-protocol/src/response.rs @@ -314,12 +314,19 @@ impl Decode for Response { } b'P' => { - position = Some(field_value.parse().map_err(|_| io::ErrorKind::InvalidData)?); + position = Some( + field_value + .parse() + .map_err(|_| io::ErrorKind::InvalidData)?, + ); } b'p' => { - internal_position = - Some(field_value.parse().map_err(|_| io::ErrorKind::InvalidData)?); + internal_position = Some( + field_value + .parse() + .map_err(|_| io::ErrorKind::InvalidData)?, + ); } b'q' => { @@ -355,7 +362,11 @@ impl Decode for Response { } b'L' => { - line = Some(field_value.parse().map_err(|_| io::ErrorKind::InvalidData)?); + line = Some( + field_value + .parse() + .map_err(|_| io::ErrorKind::InvalidData)?, + ); } b'R' => { @@ -718,7 +729,10 @@ mod tests { let message = Response::decode(src)?; assert_eq!(message.severity(), Severity::Notice); - assert_eq!(message.message(), "extension \"uuid-ossp\" already exists, skipping"); + assert_eq!( + message.message(), + "extension \"uuid-ossp\" already exists, skipping" + ); assert_eq!(message.code(), "42710"); assert_eq!(message.file(), Some("extension.c")); assert_eq!(message.line(), Some(1656)); diff --git a/sqlx-postgres-protocol/src/startup_message.rs b/sqlx-postgres-protocol/src/startup_message.rs index 577e523f..515e0655 100644 --- a/sqlx-postgres-protocol/src/startup_message.rs +++ b/sqlx-postgres-protocol/src/startup_message.rs @@ -47,7 +47,10 @@ pub struct StartupMessageBuilder { impl Default for StartupMessageBuilder { fn default() -> Self { - StartupMessageBuilder { version: (3, 0), params: BytesMut::with_capacity(156) } + StartupMessageBuilder { + version: (3, 0), + params: BytesMut::with_capacity(156), + } } } @@ -76,7 +79,10 @@ impl StartupMessageBuilder { self.params.reserve(1); self.params.put_u8(0); - StartupMessage { version: self.version, params: self.params.freeze() } + StartupMessage { + version: self.version, + params: self.params.freeze(), + } } } diff --git a/sqlx-postgres/src/connection/establish.rs b/sqlx-postgres/src/connection/establish.rs index 7ce93623..a2efa7bd 100644 --- a/sqlx-postgres/src/connection/establish.rs +++ b/sqlx-postgres/src/connection/establish.rs @@ -48,7 +48,10 @@ pub async fn establish<'a, 'b: 'a>( Message::Authentication(Authentication::CleartextPassword) => { // FIXME: Should error early (before send) if the user did not supply a password - conn.send(PasswordMessage::cleartext(options.password.unwrap_or_default())).await?; + conn.send(PasswordMessage::cleartext( + options.password.unwrap_or_default(), + )) + .await?; } Message::Authentication(Authentication::Md5Password { salt }) => { diff --git a/sqlx-postgres/src/connection/mod.rs b/sqlx-postgres/src/connection/mod.rs index a450e413..b1584188 100644 --- a/sqlx-postgres/src/connection/mod.rs +++ b/sqlx-postgres/src/connection/mod.rs @@ -117,8 +117,6 @@ async fn receiver( } while len > 0 { - log::trace!("rbuf: {:?}", rbuf); - let size = rbuf.len(); let message = Message::decode(&mut rbuf)?; len -= size - rbuf.len(); diff --git a/src/main.rs b/src/main.rs index c46faa4e..9c9e27e9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,11 @@ async fn main() -> Result<(), failure::Error> { env_logger::try_init()?; let conn = Connection::establish( - ConnectOptions::new().port(5433).user("postgres").password("password"), + ConnectOptions::new() + .host("127.0.0.1") + .port(5433) + .user("postgres") + .password("password"), ) .await?;