@@ -13,7 +13,7 @@ use std::fmt;
1313use std:: fmt:: Display ;
1414use std:: time:: Duration ;
1515
16- macro_rules! initiate_struct {
16+ macro_rules! initialize_struct {
1717 ( $struct_type: ident, $hash_map: expr, $( $field: literal) ,+) =>{
1818 paste!{
1919 $struct_type{
@@ -119,40 +119,37 @@ impl CombinedParams {
119119 delimiter : char ,
120120 expected_collection : & [ ( & str , CombinedParamsDataTypes ) ] ,
121121 ) -> Result < HashMap < String , CombinedParamsValueRetriever > , String > {
122- let check = |count : usize | {
123- if count != expected_collection. len ( ) {
124- return Err ( format ! (
125- "Wrong number of values: expected {} but {} supplied{}" ,
126- expected_collection. len( ) ,
127- count,
128- if count == 1 {
129- format!( ". Did you use the correct delimiter '{}'?" , delimiter)
130- } else {
131- "" . to_string( )
132- }
133- ) ) ;
134- }
135- Ok ( ( ) )
136- } ;
137122 let pieces: Vec < & str > = input. split ( delimiter) . collect ( ) ;
138- check ( pieces. len ( ) ) ?;
123+ let param_count = pieces. len ( ) ;
124+ let expected_param_count = expected_collection. len ( ) ;
125+ if param_count != expected_param_count {
126+ return Err ( format ! (
127+ "Wrong number of values: expected {} but {} supplied{}" ,
128+ expected_param_count,
129+ param_count,
130+ if param_count == 1 {
131+ format!( ". Did you use the correct delimiter '{}'?" , delimiter)
132+ } else {
133+ "" . to_string( )
134+ }
135+ ) ) ;
136+ }
139137 let zipped = pieces. into_iter ( ) . zip ( expected_collection. iter ( ) ) ;
140- Ok ( zipped
141- . map ( |( piece, ( param_name, data_type) ) | {
142- (
143- param_name. to_string ( ) ,
144- CombinedParamsValueRetriever :: parse ( piece, data_type) . expectv ( "numeric value" ) ,
145- )
146- } )
147- . collect ( ) )
138+ let remapped_pairs = zipped. map ( |( piece, ( param_name, data_type) ) | {
139+ (
140+ param_name. to_string ( ) ,
141+ CombinedParamsValueRetriever :: parse ( piece, data_type) . expectv ( "numeric value" ) ,
142+ )
143+ } ) ;
144+ Ok ( HashMap :: from_iter ( remapped_pairs) )
148145 }
149146
150147 fn initialize_objects (
151148 & self ,
152149 parsed_values : HashMap < String , CombinedParamsValueRetriever > ,
153150 ) -> Self {
154151 match self {
155- Self :: RatePack ( Uninitialized ) => Self :: RatePack ( Initialized ( initiate_struct ! (
152+ Self :: RatePack ( Uninitialized ) => Self :: RatePack ( Initialized ( initialize_struct ! (
156153 RatePack ,
157154 & parsed_values,
158155 "routing_byte_rate" ,
@@ -161,7 +158,7 @@ impl CombinedParams {
161158 "exit_service_rate"
162159 ) ) ) ,
163160 Self :: PaymentThresholds ( Uninitialized ) => {
164- Self :: PaymentThresholds ( Initialized ( initiate_struct ! (
161+ Self :: PaymentThresholds ( Initialized ( initialize_struct ! (
165162 PaymentThresholds ,
166163 & parsed_values,
167164 "maturity_threshold_sec" ,
@@ -173,7 +170,7 @@ impl CombinedParams {
173170 ) ) )
174171 }
175172 Self :: ScanIntervals ( Uninitialized ) => {
176- Self :: ScanIntervals ( Initialized ( initiate_struct ! (
173+ Self :: ScanIntervals ( Initialized ( initialize_struct ! (
177174 ScanIntervals ,
178175 & parsed_values,
179176 Duration :: from_secs,
@@ -183,7 +180,7 @@ impl CombinedParams {
183180 ) ) )
184181 }
185182 _ => panic ! (
186- "should be called only on uninitialized object, not: {:?}" ,
183+ "should be called only on an uninitialized object, not: {:?}" ,
187184 self
188185 ) ,
189186 }
@@ -213,7 +210,7 @@ impl From<&CombinedParams> for &[(&str, CombinedParamsDataTypes)] {
213210 ( "receivable_scan_interval" , U64 ) ,
214211 ] ,
215212 _ => panic ! (
216- "should be called only on uninitialized object, not: {:?}" ,
213+ "should be called only on an uninitialized object, not: {:?}" ,
217214 params
218215 ) ,
219216 }
@@ -433,7 +430,7 @@ mod tests {
433430 assert_eq ! (
434431 panic_1_msg,
435432 & format!(
436- "should be called only on uninitialized object, not: RatePack(Initialized({:?}))" ,
433+ "should be called only on an uninitialized object, not: RatePack(Initialized({:?}))" ,
437434 DEFAULT_RATE_PACK
438435 )
439436 ) ;
@@ -449,7 +446,7 @@ mod tests {
449446 assert_eq ! (
450447 panic_2_msg,
451448 & format!(
452- "should be called only on uninitialized object, not: PaymentThresholds(Initialized({:?}))" ,
449+ "should be called only on an uninitialized object, not: PaymentThresholds(Initialized({:?}))" ,
453450 PaymentThresholds :: default ( )
454451 )
455452 ) ;
@@ -464,7 +461,7 @@ mod tests {
464461 assert_eq ! (
465462 panic_3_msg,
466463 & format!(
467- "should be called only on uninitialized object, not: ScanIntervals(Initialized({:?}))" ,
464+ "should be called only on an uninitialized object, not: ScanIntervals(Initialized({:?}))" ,
468465 * TEST_SCAN_INTERVALS
469466 )
470467 ) ;
@@ -482,7 +479,7 @@ mod tests {
482479 assert_eq ! (
483480 panic_1_msg,
484481 & format!(
485- "should be called only on uninitialized object, not: RatePack(Initialized({:?}))" ,
482+ "should be called only on an uninitialized object, not: RatePack(Initialized({:?}))" ,
486483 DEFAULT_RATE_PACK
487484 )
488485 ) ;
@@ -497,7 +494,7 @@ mod tests {
497494 assert_eq ! (
498495 panic_2_msg,
499496 & format!(
500- "should be called only on uninitialized object, not: PaymentThresholds(Initialized({:?}))" ,
497+ "should be called only on an uninitialized object, not: PaymentThresholds(Initialized({:?}))" ,
501498 PaymentThresholds :: default ( )
502499 )
503500 ) ;
@@ -512,7 +509,7 @@ mod tests {
512509 assert_eq ! (
513510 panic_3_msg,
514511 & format!(
515- "should be called only on uninitialized object, not: ScanIntervals(Initialized({:?}))" ,
512+ "should be called only on an uninitialized object, not: ScanIntervals(Initialized({:?}))" ,
516513 * TEST_SCAN_INTERVALS
517514 )
518515 ) ;
0 commit comments