mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-20 00:54:18 +00:00
Minor clean up
This commit is contained in:
@@ -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();
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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)?;
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user