@@ -227,10 +227,10 @@ impl Config {
227227 let value = Value :: try_from ( value)
228228 . with_context ( || "Unable to represent the item as a JSON Value" ) ?;
229229
230- if index. starts_with ( "book." ) {
231- self . book . update_value ( & index [ 5 .. ] , value) ;
232- } else if index. starts_with ( "build." ) {
233- self . build . update_value ( & index [ 6 .. ] , value) ;
230+ if let Some ( key ) = index. strip_prefix ( "book." ) {
231+ self . book . update_value ( key , value) ;
232+ } else if let Some ( key ) = index. strip_prefix ( "build." ) {
233+ self . build . update_value ( key , value) ;
234234 } else {
235235 self . rest . insert ( index, value) ;
236236 }
@@ -371,15 +371,8 @@ impl Serialize for Config {
371371}
372372
373373fn parse_env ( key : & str ) -> Option < String > {
374- const PREFIX : & str = "MDBOOK_" ;
375-
376- if key. starts_with ( PREFIX ) {
377- let key = & key[ PREFIX . len ( ) ..] ;
378-
379- Some ( key. to_lowercase ( ) . replace ( "__" , "." ) . replace ( "_" , "-" ) )
380- } else {
381- None
382- }
374+ key. strip_prefix ( "MDBOOK_" )
375+ . map ( |key| key. to_lowercase ( ) . replace ( "__" , "." ) . replace ( '_' , "-" ) )
383376}
384377
385378fn is_legacy_format ( table : & Value ) -> bool {
@@ -828,7 +821,7 @@ mod tests {
828821 "# ;
829822
830823 let got = Config :: from_str ( src) . unwrap ( ) ;
831- assert_eq ! ( got. html_config( ) . unwrap( ) . playground. runnable, false ) ;
824+ assert ! ( ! got. html_config( ) . unwrap( ) . playground. runnable) ;
832825 }
833826
834827 #[ test]
@@ -1037,7 +1030,7 @@ mod tests {
10371030 fn encode_env_var ( key : & str ) -> String {
10381031 format ! (
10391032 "MDBOOK_{}" ,
1040- key. to_uppercase( ) . replace( '.' , "__" ) . replace( "-" , "_" )
1033+ key. to_uppercase( ) . replace( '.' , "__" ) . replace( '-' , "_" )
10411034 )
10421035 }
10431036
@@ -1061,11 +1054,10 @@ mod tests {
10611054 }
10621055
10631056 #[ test]
1064- #[ allow( clippy:: approx_constant) ]
10651057 fn update_config_using_env_var_and_complex_value ( ) {
10661058 let mut cfg = Config :: default ( ) ;
10671059 let key = "foo-bar.baz" ;
1068- let value = json ! ( { "array" : [ 1 , 2 , 3 ] , "number" : 3.14 } ) ;
1060+ let value = json ! ( { "array" : [ 1 , 2 , 3 ] , "number" : 13.37 } ) ;
10691061 let value_str = serde_json:: to_string ( & value) . unwrap ( ) ;
10701062
10711063 assert ! ( cfg. get( key) . is_none( ) ) ;
@@ -1184,15 +1176,15 @@ mod tests {
11841176 "# ;
11851177 let got = Config :: from_str ( src) . unwrap ( ) ;
11861178 let html_config = got. html_config ( ) . unwrap ( ) ;
1187- assert_eq ! ( html_config. print. enable, false ) ;
1188- assert_eq ! ( html_config. print. page_break, true ) ;
1179+ assert ! ( ! html_config. print. enable) ;
1180+ assert ! ( html_config. print. page_break) ;
11891181 let src = r#"
11901182 [output.html.print]
11911183 page-break = false
11921184 "# ;
11931185 let got = Config :: from_str ( src) . unwrap ( ) ;
11941186 let html_config = got. html_config ( ) . unwrap ( ) ;
1195- assert_eq ! ( html_config. print. enable, true ) ;
1196- assert_eq ! ( html_config. print. page_break, false ) ;
1187+ assert ! ( html_config. print. enable) ;
1188+ assert ! ( ! html_config. print. page_break) ;
11971189 }
11981190}
0 commit comments