Fixed all clippy warnings.

This commit is contained in:
Mohammad Dashti
2023-10-06 13:20:19 -07:00
parent c4fb72b9fc
commit d1f3b847e3
16 changed files with 233 additions and 286 deletions

View File

@@ -197,12 +197,8 @@ impl ServerParameters {
key = "DateStyle".to_string();
};
if TRACKED_PARAMETERS.contains(&key) {
if TRACKED_PARAMETERS.contains(&key) || startup {
self.parameters.insert(key, value);
} else {
if startup {
self.parameters.insert(key, value);
}
}
}
@@ -332,6 +328,7 @@ pub struct Server {
impl Server {
/// Pretend to be the Postgres client and connect to the server given host, port and credentials.
/// Perform the authentication and return the server in a ready for query state.
#[allow(clippy::too_many_arguments)]
pub async fn startup(
address: &Address,
user: &User,
@@ -440,10 +437,7 @@ impl Server {
// Something else?
m => {
return Err(Error::SocketError(format!(
"Unknown message: {}",
m as char
)));
return Err(Error::SocketError(format!("Unknown message: {}", { m })));
}
}
} else {
@@ -461,26 +455,17 @@ impl Server {
None => &user.username,
};
let password = match user.server_password {
Some(ref server_password) => Some(server_password),
None => match user.password {
Some(ref password) => Some(password),
None => None,
},
};
let password = user.server_password.as_ref();
startup(&mut stream, username, database).await?;
let mut process_id: i32 = 0;
let mut secret_key: i32 = 0;
let server_identifier = ServerIdentifier::new(username, &database);
let server_identifier = ServerIdentifier::new(username, database);
// We'll be handling multiple packets, but they will all be structured the same.
// We'll loop here until this exchange is complete.
let mut scram: Option<ScramSha256> = match password {
Some(password) => Some(ScramSha256::new(password)),
None => None,
};
let mut scram: Option<ScramSha256> = password.map(|password| ScramSha256::new(password));
let mut server_parameters = ServerParameters::new();
@@ -882,7 +867,7 @@ impl Server {
self.mirror_send(messages);
self.stats().data_sent(messages.len());
match write_all_flush(&mut self.stream, &messages).await {
match write_all_flush(&mut self.stream, messages).await {
Ok(_) => {
// Successfully sent to server
self.last_activity = SystemTime::now();
@@ -1359,16 +1344,14 @@ impl Server {
}
pub fn mirror_send(&mut self, bytes: &BytesMut) {
match self.mirror_manager.as_mut() {
Some(manager) => manager.send(bytes),
None => (),
if let Some(manager) = self.mirror_manager.as_mut() {
manager.send(bytes)
}
}
pub fn mirror_disconnect(&mut self) {
match self.mirror_manager.as_mut() {
Some(manager) => manager.disconnect(),
None => (),
if let Some(manager) = self.mirror_manager.as_mut() {
manager.disconnect()
}
}
@@ -1397,7 +1380,7 @@ impl Server {
server.send(&simple_query(query)).await?;
let mut message = server.recv(None).await?;
Ok(parse_query_message(&mut message).await?)
parse_query_message(&mut message).await
}
}