Skip to content

Commit ca492bc

Browse files
brandonpikeCommanderKeynes
authored andcommitted
Fix lint warnings for rust-1.79 (#769)
2 things that are recommended by rust-lang - implementing `std::fmt::Display` rather than ToString (1) and using clone_from (2). [1] https://rust-lang.github.io/rust-clippy/master/index.html#/to_string_trait_impl [2] https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones Signed-off-by: Brandon Pike <pikebrandon@att.net>
1 parent 5c454df commit ca492bc

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

src/config.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ pub enum Role {
3838
Mirror,
3939
}
4040

41-
impl ToString for Role {
42-
fn to_string(&self) -> String {
43-
match *self {
44-
Role::Primary => "primary".to_string(),
45-
Role::Replica => "replica".to_string(),
46-
Role::Mirror => "mirror".to_string(),
41+
impl std::fmt::Display for Role {
42+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43+
match self {
44+
Role::Primary => write!(f, "primary"),
45+
Role::Replica => write!(f, "replica"),
46+
Role::Mirror => write!(f, "mirror"),
4747
}
4848
}
4949
}
@@ -488,11 +488,11 @@ pub enum PoolMode {
488488
Session,
489489
}
490490

491-
impl ToString for PoolMode {
492-
fn to_string(&self) -> String {
493-
match *self {
494-
PoolMode::Transaction => "transaction".to_string(),
495-
PoolMode::Session => "session".to_string(),
491+
impl std::fmt::Display for PoolMode {
492+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
493+
match self {
494+
PoolMode::Transaction => write!(f, "transaction"),
495+
PoolMode::Session => write!(f, "session"),
496496
}
497497
}
498498
}
@@ -505,12 +505,13 @@ pub enum LoadBalancingMode {
505505
#[serde(alias = "loc", alias = "LOC", alias = "least_outstanding_connections")]
506506
LeastOutstandingConnections,
507507
}
508-
impl ToString for LoadBalancingMode {
509-
fn to_string(&self) -> String {
510-
match *self {
511-
LoadBalancingMode::Random => "random".to_string(),
508+
509+
impl std::fmt::Display for LoadBalancingMode {
510+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
511+
match self {
512+
LoadBalancingMode::Random => write!(f, "random"),
512513
LoadBalancingMode::LeastOutstandingConnections => {
513-
"least_outstanding_connections".to_string()
514+
write!(f, "least_outstanding_connections")
514515
}
515516
}
516517
}
@@ -1011,15 +1012,17 @@ impl Config {
10111012
pub fn fill_up_auth_query_config(&mut self) {
10121013
for (_name, pool) in self.pools.iter_mut() {
10131014
if pool.auth_query.is_none() {
1014-
pool.auth_query = self.general.auth_query.clone();
1015+
pool.auth_query.clone_from(&self.general.auth_query);
10151016
}
10161017

10171018
if pool.auth_query_user.is_none() {
1018-
pool.auth_query_user = self.general.auth_query_user.clone();
1019+
pool.auth_query_user
1020+
.clone_from(&self.general.auth_query_user);
10191021
}
10201022

10211023
if pool.auth_query_password.is_none() {
1022-
pool.auth_query_password = self.general.auth_query_password.clone();
1024+
pool.auth_query_password
1025+
.clone_from(&self.general.auth_query_password);
10231026
}
10241027
}
10251028
}
@@ -1167,7 +1170,7 @@ impl Config {
11671170
"Default max server lifetime: {}ms",
11681171
self.general.server_lifetime
11691172
);
1170-
info!("Sever round robin: {}", self.general.server_round_robin);
1173+
info!("Server round robin: {}", self.general.server_round_robin);
11711174
match self.general.tls_certificate.clone() {
11721175
Some(tls_certificate) => {
11731176
info!("TLS certificate: {}", tls_certificate);

src/sharding.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ pub enum ShardingFunction {
1414
Sha1,
1515
}
1616

17-
impl ToString for ShardingFunction {
18-
fn to_string(&self) -> String {
19-
match *self {
20-
ShardingFunction::PgBigintHash => "pg_bigint_hash".to_string(),
21-
ShardingFunction::Sha1 => "sha1".to_string(),
17+
impl std::fmt::Display for ShardingFunction {
18+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19+
match self {
20+
ShardingFunction::PgBigintHash => write!(f, "pg_bigint_hash"),
21+
ShardingFunction::Sha1 => write!(f, "sha1"),
2222
}
2323
}
2424
}

0 commit comments

Comments
 (0)