Skip to content

Added clippy to CI and fixed all clippy warnings #613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Oct 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
client.rs clippy fixes.
  • Loading branch information
mdashti committed Oct 10, 2023
commit 9c6b143bc935ea986d476bcb82562f5c8b83c952
39 changes: 16 additions & 23 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub async fn client_entrypoint(
// Client requested a TLS connection.
Ok((ClientConnectionType::Tls, _)) => {
// TLS settings are configured, will setup TLS now.
if tls_certificate != None {
if tls_certificate.is_some() {
debug!("Accepting TLS request");

let mut yes = BytesMut::new();
Expand Down Expand Up @@ -448,7 +448,7 @@ where
None => "pgcat",
};

let client_identifier = ClientIdentifier::new(&application_name, &username, &pool_name);
let client_identifier = ClientIdentifier::new(application_name, username, pool_name);

let admin = ["pgcat", "pgbouncer"]
.iter()
Expand Down Expand Up @@ -795,7 +795,7 @@ where
let mut will_prepare = false;

let client_identifier = ClientIdentifier::new(
&self.server_parameters.get_application_name(),
self.server_parameters.get_application_name(),
&self.username,
&self.pool_name,
);
Expand Down Expand Up @@ -982,15 +982,11 @@ where
}

// Check on plugin results.
match plugin_output {
Some(PluginOutput::Deny(error)) => {
self.buffer.clear();
error_response(&mut self.write, &error).await?;
plugin_output = None;
continue;
}

_ => (),
if let Some(PluginOutput::Deny(error)) = plugin_output {
self.buffer.clear();
error_response(&mut self.write, &error).await?;
plugin_output = None;
continue;
};

// Check if the pool is paused and wait until it's resumed.
Expand Down Expand Up @@ -1267,7 +1263,7 @@ where

// Safe to unwrap because we know this message has a certain length and has the code
// This reads the first byte without advancing the internal pointer and mutating the bytes
let code = *message.get(0).unwrap() as char;
let code = *message.first().unwrap() as char;

trace!("Message: {}", code);

Expand Down Expand Up @@ -1325,7 +1321,7 @@ where
self.stats.transaction();
server
.stats()
.transaction(&self.server_parameters.get_application_name());
.transaction(self.server_parameters.get_application_name());

// Release server back to the pool if we are in transaction mode.
// If we are in session mode, we keep the server until the client disconnects.
Expand Down Expand Up @@ -1400,13 +1396,10 @@ where
let close: Close = (&message).try_into()?;

if close.is_prepared_statement() && !close.anonymous() {
match self.prepared_statements.get(&close.name) {
Some(parse) => {
server.will_close(&parse.generated_name);
}

if let Some(parse) = self.prepared_statements.get(&close.name) {
server.will_close(&parse.generated_name);
} else {
// A prepared statement slipped through? Not impossible, since we don't support PREPARE yet.
None => (),
};
}
}
Expand Down Expand Up @@ -1445,7 +1438,7 @@ where

self.buffer.put(&message[..]);

let first_message_code = (*self.buffer.get(0).unwrap_or(&0)) as char;
let first_message_code = (*self.buffer.first().unwrap_or(&0)) as char;

// Almost certainly true
if first_message_code == 'P' && !prepared_statements_enabled {
Expand Down Expand Up @@ -1477,7 +1470,7 @@ where
self.stats.transaction();
server
.stats()
.transaction(&self.server_parameters.get_application_name());
.transaction(self.server_parameters.get_application_name());

// Release server back to the pool if we are in transaction mode.
// If we are in session mode, we keep the server until the client disconnects.
Expand Down Expand Up @@ -1739,7 +1732,7 @@ where
client_stats.query();
server.stats().query(
Instant::now().duration_since(query_start).as_millis() as u64,
&self.server_parameters.get_application_name(),
self.server_parameters.get_application_name(),
);

Ok(())
Expand Down