@@ -67,7 +67,10 @@ impl ReplicaConfig {
6767 /// Creates a new replica config with the given URL and weight.
6868 #[ must_use]
6969 pub fn with_weight ( url : String , weight : u32 ) -> Self {
70- Self { url, weight : weight. max ( 1 ) }
70+ Self {
71+ url,
72+ weight : weight. max ( 1 ) ,
73+ }
7174 }
7275}
7376
@@ -421,7 +424,9 @@ impl DriverOptionsArg {
421424 _ => {
422425 return Err ( SqlxError :: config (
423426 "read_replicas" ,
424- format ! ( "element at index {i}: 'weight' must be an integer" ) ,
427+ format ! (
428+ "element at index {i}: 'weight' must be an integer"
429+ ) ,
425430 ) ) ;
426431 }
427432 } ;
@@ -430,7 +435,9 @@ impl DriverOptionsArg {
430435 _ => {
431436 return Err ( SqlxError :: config (
432437 "read_replicas" ,
433- format ! ( "element at index {i} must be a string or ['url' => ..., 'weight' => ...]" ) ,
438+ format ! (
439+ "element at index {i} must be a string or ['url' => ..., 'weight' => ...]"
440+ ) ,
434441 ) ) ;
435442 }
436443 }
@@ -461,9 +468,7 @@ impl DriverOptionsArg {
461468 None | Some ( ParameterValue :: Null ) => DEFAULT_RETRY_INITIAL_BACKOFF ,
462469 Some ( ParameterValue :: String ( value) ) => parse_duration:: parse ( value)
463470 . map_err ( |e| SqlxError :: config ( "retry_initial_backoff" , e. to_string ( ) ) ) ?,
464- Some ( ParameterValue :: Int ( value) ) => {
465- Duration :: from_secs ( u64:: try_from ( * value) ?)
466- }
471+ Some ( ParameterValue :: Int ( value) ) => Duration :: from_secs ( u64:: try_from ( * value) ?) ,
467472 _ => {
468473 return Err ( SqlxError :: config (
469474 "retry_initial_backoff" ,
@@ -475,9 +480,7 @@ impl DriverOptionsArg {
475480 None | Some ( ParameterValue :: Null ) => DEFAULT_RETRY_MAX_BACKOFF ,
476481 Some ( ParameterValue :: String ( value) ) => parse_duration:: parse ( value)
477482 . map_err ( |e| SqlxError :: config ( "retry_max_backoff" , e. to_string ( ) ) ) ?,
478- Some ( ParameterValue :: Int ( value) ) => {
479- Duration :: from_secs ( u64:: try_from ( * value) ?)
480- }
483+ Some ( ParameterValue :: Int ( value) ) => Duration :: from_secs ( u64:: try_from ( * value) ?) ,
481484 _ => {
482485 return Err ( SqlxError :: config (
483486 "retry_max_backoff" ,
@@ -491,10 +494,7 @@ impl DriverOptionsArg {
491494 ParameterValue :: Float ( f) => Ok ( * f) ,
492495 #[ allow( clippy:: cast_precision_loss) ]
493496 ParameterValue :: Int ( n) => Ok ( * n as f64 ) ,
494- _ => Err ( SqlxError :: config (
495- "retry_multiplier" ,
496- "must be a number" ,
497- ) ) ,
497+ _ => Err ( SqlxError :: config ( "retry_multiplier" , "must be a number" ) ) ,
498498 } ,
499499 ) ?,
500500 } ,
@@ -547,7 +547,10 @@ mod tests {
547547 #[ test]
548548 fn test_read_replicas_simple_strings ( ) {
549549 let driver_options = DriverOptionsArg :: Options ( BTreeMap :: from_iter ( [
550- ( DriverOptions :: OPT_URL . into ( ) , "postgres://primary/db" . into ( ) ) ,
550+ (
551+ DriverOptions :: OPT_URL . into ( ) ,
552+ "postgres://primary/db" . into ( ) ,
553+ ) ,
551554 (
552555 DriverOptions :: OPT_READ_REPLICAS . into ( ) ,
553556 ParameterValue :: Array ( vec ! [
@@ -560,16 +563,25 @@ mod tests {
560563 . unwrap ( ) ;
561564
562565 assert_eq ! ( driver_options. read_replicas. len( ) , 2 ) ;
563- assert_eq ! ( driver_options. read_replicas[ 0 ] . url, "postgres://replica1/db" ) ;
566+ assert_eq ! (
567+ driver_options. read_replicas[ 0 ] . url,
568+ "postgres://replica1/db"
569+ ) ;
564570 assert_eq ! ( driver_options. read_replicas[ 0 ] . weight, 1 ) ;
565- assert_eq ! ( driver_options. read_replicas[ 1 ] . url, "postgres://replica2/db" ) ;
571+ assert_eq ! (
572+ driver_options. read_replicas[ 1 ] . url,
573+ "postgres://replica2/db"
574+ ) ;
566575 assert_eq ! ( driver_options. read_replicas[ 1 ] . weight, 1 ) ;
567576 }
568577
569578 #[ test]
570579 fn test_read_replicas_with_weights ( ) {
571580 let driver_options = DriverOptionsArg :: Options ( BTreeMap :: from_iter ( [
572- ( DriverOptions :: OPT_URL . into ( ) , "postgres://primary/db" . into ( ) ) ,
581+ (
582+ DriverOptions :: OPT_URL . into ( ) ,
583+ "postgres://primary/db" . into ( ) ,
584+ ) ,
573585 (
574586 DriverOptions :: OPT_READ_REPLICAS . into ( ) ,
575587 ParameterValue :: Array ( vec ! [
@@ -588,16 +600,25 @@ mod tests {
588600 . unwrap ( ) ;
589601
590602 assert_eq ! ( driver_options. read_replicas. len( ) , 2 ) ;
591- assert_eq ! ( driver_options. read_replicas[ 0 ] . url, "postgres://replica1/db" ) ;
603+ assert_eq ! (
604+ driver_options. read_replicas[ 0 ] . url,
605+ "postgres://replica1/db"
606+ ) ;
592607 assert_eq ! ( driver_options. read_replicas[ 0 ] . weight, 3 ) ;
593- assert_eq ! ( driver_options. read_replicas[ 1 ] . url, "postgres://replica2/db" ) ;
608+ assert_eq ! (
609+ driver_options. read_replicas[ 1 ] . url,
610+ "postgres://replica2/db"
611+ ) ;
594612 assert_eq ! ( driver_options. read_replicas[ 1 ] . weight, 1 ) ;
595613 }
596614
597615 #[ test]
598616 fn test_read_replicas_mixed_format ( ) {
599617 let driver_options = DriverOptionsArg :: Options ( BTreeMap :: from_iter ( [
600- ( DriverOptions :: OPT_URL . into ( ) , "postgres://primary/db" . into ( ) ) ,
618+ (
619+ DriverOptions :: OPT_URL . into ( ) ,
620+ "postgres://primary/db" . into ( ) ,
621+ ) ,
601622 (
602623 DriverOptions :: OPT_READ_REPLICAS . into ( ) ,
603624 ParameterValue :: Array ( vec ! [
@@ -620,7 +641,10 @@ mod tests {
620641 #[ test]
621642 fn test_read_replicas_default_weight_when_missing ( ) {
622643 let driver_options = DriverOptionsArg :: Options ( BTreeMap :: from_iter ( [
623- ( DriverOptions :: OPT_URL . into ( ) , "postgres://primary/db" . into ( ) ) ,
644+ (
645+ DriverOptions :: OPT_URL . into ( ) ,
646+ "postgres://primary/db" . into ( ) ,
647+ ) ,
624648 (
625649 DriverOptions :: OPT_READ_REPLICAS . into ( ) ,
626650 ParameterValue :: Array ( vec ! [ ParameterValue :: Object ( BTreeMap :: from_iter( [ (
@@ -638,7 +662,10 @@ mod tests {
638662 #[ test]
639663 fn test_read_replicas_empty_array ( ) {
640664 let driver_options = DriverOptionsArg :: Options ( BTreeMap :: from_iter ( [
641- ( DriverOptions :: OPT_URL . into ( ) , "postgres://primary/db" . into ( ) ) ,
665+ (
666+ DriverOptions :: OPT_URL . into ( ) ,
667+ "postgres://primary/db" . into ( ) ,
668+ ) ,
642669 (
643670 DriverOptions :: OPT_READ_REPLICAS . into ( ) ,
644671 ParameterValue :: Array ( vec ! [ ] ) ,
@@ -653,7 +680,10 @@ mod tests {
653680 #[ test]
654681 fn test_read_replicas_missing_url_error ( ) {
655682 let result = DriverOptionsArg :: Options ( BTreeMap :: from_iter ( [
656- ( DriverOptions :: OPT_URL . into ( ) , "postgres://primary/db" . into ( ) ) ,
683+ (
684+ DriverOptions :: OPT_URL . into ( ) ,
685+ "postgres://primary/db" . into ( ) ,
686+ ) ,
657687 (
658688 DriverOptions :: OPT_READ_REPLICAS . into ( ) ,
659689 ParameterValue :: Array ( vec ! [ ParameterValue :: Object ( BTreeMap :: from_iter( [ (
0 commit comments