@@ -236,18 +236,14 @@ impl Default for User {
236
236
237
237
impl User {
238
238
fn validate ( & self ) -> Result < ( ) , Error > {
239
- match self . min_pool_size {
240
- Some ( min_pool_size) => {
241
- if min_pool_size > self . pool_size {
242
- error ! (
243
- "min_pool_size of {} cannot be larger than pool_size of {}" ,
244
- min_pool_size, self . pool_size
245
- ) ;
246
- return Err ( Error :: BadConfig ) ;
247
- }
239
+ if let Some ( min_pool_size) = self . min_pool_size {
240
+ if min_pool_size > self . pool_size {
241
+ error ! (
242
+ "min_pool_size of {} cannot be larger than pool_size of {}" ,
243
+ min_pool_size, self . pool_size
244
+ ) ;
245
+ return Err ( Error :: BadConfig ) ;
248
246
}
249
-
250
- None => ( ) ,
251
247
} ;
252
248
253
249
Ok ( ( ) )
@@ -677,9 +673,9 @@ impl Pool {
677
673
Some ( key) => {
678
674
// No quotes in the key so we don't have to compare quoted
679
675
// to unquoted idents.
680
- let key = key. replace ( " \" " , "" ) ;
676
+ let key = key. replace ( '\"' , "" ) ;
681
677
682
- if key. split ( "." ) . count ( ) != 2 {
678
+ if key. split ( '.' ) . count ( ) != 2 {
683
679
error ! (
684
680
"automatic_sharding_key '{}' must be fully qualified, e.g. t.{}`" ,
685
681
key, key
@@ -692,17 +688,14 @@ impl Pool {
692
688
None => None ,
693
689
} ;
694
690
695
- match self . default_shard {
696
- DefaultShard :: Shard ( shard_number) => {
697
- if shard_number >= self . shards . len ( ) {
698
- error ! ( "Invalid shard {:?}" , shard_number) ;
699
- return Err ( Error :: BadConfig ) ;
700
- }
691
+ if let DefaultShard :: Shard ( shard_number) = self . default_shard {
692
+ if shard_number >= self . shards . len ( ) {
693
+ error ! ( "Invalid shard {:?}" , shard_number) ;
694
+ return Err ( Error :: BadConfig ) ;
701
695
}
702
- _ => ( ) ,
703
696
}
704
697
705
- for ( _ , user) in & self . users {
698
+ for user in self . users . values ( ) {
706
699
user. validate ( ) ?;
707
700
}
708
701
@@ -777,8 +770,8 @@ impl<'de> serde::Deserialize<'de> for DefaultShard {
777
770
D : Deserializer < ' de > ,
778
771
{
779
772
let s = String :: deserialize ( deserializer) ?;
780
- if s . starts_with ( "shard_" ) {
781
- let shard = s[ 6 .. ] . parse :: < usize > ( ) . map_err ( serde:: de:: Error :: custom) ?;
773
+ if let Some ( s ) = s . strip_prefix ( "shard_" ) {
774
+ let shard = s. parse :: < usize > ( ) . map_err ( serde:: de:: Error :: custom) ?;
782
775
return Ok ( DefaultShard :: Shard ( shard) ) ;
783
776
}
784
777
@@ -874,7 +867,7 @@ pub trait Plugin {
874
867
impl std:: fmt:: Display for Plugins {
875
868
fn fmt ( & self , f : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
876
869
fn is_enabled < T : Plugin > ( arg : Option < & T > ) -> bool {
877
- if let Some ( ref arg) = arg {
870
+ if let Some ( arg) = arg {
878
871
arg. is_enabled ( )
879
872
} else {
880
873
false
@@ -955,6 +948,7 @@ pub struct Query {
955
948
}
956
949
957
950
impl Query {
951
+ #[ allow( clippy:: needless_range_loop) ]
958
952
pub fn substitute ( & mut self , db : & str , user : & str ) {
959
953
for col in self . result . iter_mut ( ) {
960
954
for i in 0 ..col. len ( ) {
@@ -1079,8 +1073,8 @@ impl From<&Config> for std::collections::HashMap<String, String> {
1079
1073
(
1080
1074
format ! ( "pools.{:?}.users" , pool_name) ,
1081
1075
pool. users
1082
- . iter ( )
1083
- . map ( |( _username , user) | & user. username )
1076
+ . values ( )
1077
+ . map ( |user| & user. username )
1084
1078
. cloned ( )
1085
1079
. collect :: < Vec < String > > ( )
1086
1080
. join ( ", " ) ,
@@ -1165,13 +1159,9 @@ impl Config {
1165
1159
Some ( tls_certificate) => {
1166
1160
info ! ( "TLS certificate: {}" , tls_certificate) ;
1167
1161
1168
- match self . general . tls_private_key . clone ( ) {
1169
- Some ( tls_private_key) => {
1170
- info ! ( "TLS private key: {}" , tls_private_key) ;
1171
- info ! ( "TLS support is enabled" ) ;
1172
- }
1173
-
1174
- None => ( ) ,
1162
+ if let Some ( tls_private_key) = self . general . tls_private_key . clone ( ) {
1163
+ info ! ( "TLS private key: {}" , tls_private_key) ;
1164
+ info ! ( "TLS support is enabled" ) ;
1175
1165
}
1176
1166
}
1177
1167
@@ -1206,8 +1196,8 @@ impl Config {
1206
1196
pool_name,
1207
1197
pool_config
1208
1198
. users
1209
- . iter ( )
1210
- . map( |( _ , user_cfg) | user_cfg. pool_size)
1199
+ . values ( )
1200
+ . map( |user_cfg| user_cfg. pool_size)
1211
1201
. sum:: <u32 >( )
1212
1202
. to_string( )
1213
1203
) ;
@@ -1377,34 +1367,31 @@ impl Config {
1377
1367
}
1378
1368
1379
1369
// Validate TLS!
1380
- match self . general . tls_certificate . clone ( ) {
1381
- Some ( tls_certificate) => {
1382
- match load_certs ( Path :: new ( & tls_certificate) ) {
1383
- Ok ( _) => {
1384
- // Cert is okay, but what about the private key?
1385
- match self . general . tls_private_key . clone ( ) {
1386
- Some ( tls_private_key) => match load_keys ( Path :: new ( & tls_private_key) ) {
1387
- Ok ( _) => ( ) ,
1388
- Err ( err) => {
1389
- error ! ( "tls_private_key is incorrectly configured: {:?}" , err) ;
1390
- return Err ( Error :: BadConfig ) ;
1391
- }
1392
- } ,
1393
-
1394
- None => {
1395
- error ! ( "tls_certificate is set, but the tls_private_key is not" ) ;
1370
+ if let Some ( tls_certificate) = self . general . tls_certificate . clone ( ) {
1371
+ match load_certs ( Path :: new ( & tls_certificate) ) {
1372
+ Ok ( _) => {
1373
+ // Cert is okay, but what about the private key?
1374
+ match self . general . tls_private_key . clone ( ) {
1375
+ Some ( tls_private_key) => match load_keys ( Path :: new ( & tls_private_key) ) {
1376
+ Ok ( _) => ( ) ,
1377
+ Err ( err) => {
1378
+ error ! ( "tls_private_key is incorrectly configured: {:?}" , err) ;
1396
1379
return Err ( Error :: BadConfig ) ;
1397
1380
}
1398
- } ;
1399
- }
1381
+ } ,
1400
1382
1401
- Err ( err) => {
1402
- error ! ( "tls_certificate is incorrectly configured: {:?}" , err) ;
1403
- return Err ( Error :: BadConfig ) ;
1404
- }
1383
+ None => {
1384
+ error ! ( "tls_certificate is set, but the tls_private_key is not" ) ;
1385
+ return Err ( Error :: BadConfig ) ;
1386
+ }
1387
+ } ;
1388
+ }
1389
+
1390
+ Err ( err) => {
1391
+ error ! ( "tls_certificate is incorrectly configured: {:?}" , err) ;
1392
+ return Err ( Error :: BadConfig ) ;
1405
1393
}
1406
1394
}
1407
- None => ( ) ,
1408
1395
} ;
1409
1396
1410
1397
for pool in self . pools . values_mut ( ) {
0 commit comments