Skip to content

Commit 62ba871

Browse files
committed
server.rs clippy fixes.
1 parent 9c6b143 commit 62ba871

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

src/server.rs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,8 @@ impl ServerParameters {
197197
key = "DateStyle".to_string();
198198
};
199199

200-
if TRACKED_PARAMETERS.contains(&key) {
200+
if TRACKED_PARAMETERS.contains(&key) || startup {
201201
self.parameters.insert(key, value);
202-
} else {
203-
if startup {
204-
self.parameters.insert(key, value);
205-
}
206202
}
207203
}
208204

@@ -332,6 +328,7 @@ pub struct Server {
332328
impl Server {
333329
/// Pretend to be the Postgres client and connect to the server given host, port and credentials.
334330
/// Perform the authentication and return the server in a ready for query state.
331+
#[allow(clippy::too_many_arguments)]
335332
pub async fn startup(
336333
address: &Address,
337334
user: &User,
@@ -440,10 +437,7 @@ impl Server {
440437

441438
// Something else?
442439
m => {
443-
return Err(Error::SocketError(format!(
444-
"Unknown message: {}",
445-
m as char
446-
)));
440+
return Err(Error::SocketError(format!("Unknown message: {}", { m })));
447441
}
448442
}
449443
} else {
@@ -461,6 +455,8 @@ impl Server {
461455
None => &user.username,
462456
};
463457

458+
#[allow(clippy::match_as_ref)]
459+
#[allow(clippy::manual_map)]
464460
let password = match user.server_password {
465461
Some(ref server_password) => Some(server_password),
466462
None => match user.password {
@@ -473,14 +469,11 @@ impl Server {
473469

474470
let mut process_id: i32 = 0;
475471
let mut secret_key: i32 = 0;
476-
let server_identifier = ServerIdentifier::new(username, &database);
472+
let server_identifier = ServerIdentifier::new(username, database);
477473

478474
// We'll be handling multiple packets, but they will all be structured the same.
479475
// We'll loop here until this exchange is complete.
480-
let mut scram: Option<ScramSha256> = match password {
481-
Some(password) => Some(ScramSha256::new(password)),
482-
None => None,
483-
};
476+
let mut scram: Option<ScramSha256> = password.map(|password| ScramSha256::new(password));
484477

485478
let mut server_parameters = ServerParameters::new();
486479

@@ -882,7 +875,7 @@ impl Server {
882875
self.mirror_send(messages);
883876
self.stats().data_sent(messages.len());
884877

885-
match write_all_flush(&mut self.stream, &messages).await {
878+
match write_all_flush(&mut self.stream, messages).await {
886879
Ok(_) => {
887880
// Successfully sent to server
888881
self.last_activity = SystemTime::now();
@@ -1359,16 +1352,14 @@ impl Server {
13591352
}
13601353

13611354
pub fn mirror_send(&mut self, bytes: &BytesMut) {
1362-
match self.mirror_manager.as_mut() {
1363-
Some(manager) => manager.send(bytes),
1364-
None => (),
1355+
if let Some(manager) = self.mirror_manager.as_mut() {
1356+
manager.send(bytes)
13651357
}
13661358
}
13671359

13681360
pub fn mirror_disconnect(&mut self) {
1369-
match self.mirror_manager.as_mut() {
1370-
Some(manager) => manager.disconnect(),
1371-
None => (),
1361+
if let Some(manager) = self.mirror_manager.as_mut() {
1362+
manager.disconnect()
13721363
}
13731364
}
13741365

@@ -1397,7 +1388,7 @@ impl Server {
13971388
server.send(&simple_query(query)).await?;
13981389
let mut message = server.recv(None).await?;
13991390

1400-
Ok(parse_query_message(&mut message).await?)
1391+
parse_query_message(&mut message).await
14011392
}
14021393
}
14031394

0 commit comments

Comments
 (0)