Skip to content

Commit cbf4d58

Browse files
authored
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 731aa04 commit cbf4d58

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
}
@@ -476,11 +476,11 @@ pub enum PoolMode {
476476
Session,
477477
}
478478

479-
impl ToString for PoolMode {
480-
fn to_string(&self) -> String {
481-
match *self {
482-
PoolMode::Transaction => "transaction".to_string(),
483-
PoolMode::Session => "session".to_string(),
479+
impl std::fmt::Display for PoolMode {
480+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
481+
match self {
482+
PoolMode::Transaction => write!(f, "transaction"),
483+
PoolMode::Session => write!(f, "session"),
484484
}
485485
}
486486
}
@@ -493,12 +493,13 @@ pub enum LoadBalancingMode {
493493
#[serde(alias = "loc", alias = "LOC", alias = "least_outstanding_connections")]
494494
LeastOutstandingConnections,
495495
}
496-
impl ToString for LoadBalancingMode {
497-
fn to_string(&self) -> String {
498-
match *self {
499-
LoadBalancingMode::Random => "random".to_string(),
496+
497+
impl std::fmt::Display for LoadBalancingMode {
498+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
499+
match self {
500+
LoadBalancingMode::Random => write!(f, "random"),
500501
LoadBalancingMode::LeastOutstandingConnections => {
501-
"least_outstanding_connections".to_string()
502+
write!(f, "least_outstanding_connections")
502503
}
503504
}
504505
}
@@ -999,15 +1000,17 @@ impl Config {
9991000
pub fn fill_up_auth_query_config(&mut self) {
10001001
for (_name, pool) in self.pools.iter_mut() {
10011002
if pool.auth_query.is_none() {
1002-
pool.auth_query = self.general.auth_query.clone();
1003+
pool.auth_query.clone_from(&self.general.auth_query);
10031004
}
10041005

10051006
if pool.auth_query_user.is_none() {
1006-
pool.auth_query_user = self.general.auth_query_user.clone();
1007+
pool.auth_query_user
1008+
.clone_from(&self.general.auth_query_user);
10071009
}
10081010

10091011
if pool.auth_query_password.is_none() {
1010-
pool.auth_query_password = self.general.auth_query_password.clone();
1012+
pool.auth_query_password
1013+
.clone_from(&self.general.auth_query_password);
10111014
}
10121015
}
10131016
}
@@ -1155,7 +1158,7 @@ impl Config {
11551158
"Default max server lifetime: {}ms",
11561159
self.general.server_lifetime
11571160
);
1158-
info!("Sever round robin: {}", self.general.server_round_robin);
1161+
info!("Server round robin: {}", self.general.server_round_robin);
11591162
match self.general.tls_certificate.clone() {
11601163
Some(tls_certificate) => {
11611164
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)