@@ -70,8 +70,7 @@ impl Default for Relax {
70
70
impl Relax {
71
71
/// Creates a strict json parser.
72
72
pub fn json ( ) -> Self {
73
- Relax {
74
- inner : Default :: default ( ) ,
73
+ Self {
75
74
comma_trailing : false ,
76
75
comma_optional : false ,
77
76
number_bin : false ,
@@ -87,31 +86,34 @@ impl Relax {
87
86
comment_slash : false ,
88
87
comment_hash : false ,
89
88
comment_block : false ,
89
+ ..Self :: default ( )
90
90
}
91
91
}
92
92
93
93
/// Creates a json5 parser.
94
94
pub fn json5 ( ) -> Self {
95
- let mut r = Self :: default ( ) ;
96
- r. comma_optional = false ;
97
- r. string_unquoted = false ;
98
- r. string_hjson_multiline = false ;
99
- r. comment_hash = false ;
100
- r. number_bin = false ;
101
- r. number_oct = false ;
102
- r
95
+ Self {
96
+ comma_optional : false ,
97
+ string_unquoted : false ,
98
+ string_hjson_multiline : false ,
99
+ comment_hash : false ,
100
+ number_bin : false ,
101
+ number_oct : false ,
102
+ ..Self :: default ( )
103
+ }
103
104
}
104
105
105
106
/// Creates a hjson parser.
106
107
pub fn hjson ( ) -> Self {
107
- let mut r = Self :: default ( ) ;
108
- r. string_json5_multiline = false ;
109
- r. number_bin = false ;
110
- r. number_hex = false ;
111
- r. number_oct = false ;
112
- r. number_plus = false ;
113
- r. number_lax_dec_point = false ;
114
- r
108
+ Self {
109
+ string_json5_multiline : false ,
110
+ number_bin : false ,
111
+ number_hex : false ,
112
+ number_oct : false ,
113
+ number_plus : false ,
114
+ number_lax_dec_point : false ,
115
+ ..Self :: default ( )
116
+ }
115
117
}
116
118
117
119
/// Parses a string into a `Document`.
@@ -217,7 +219,7 @@ impl Relax {
217
219
"hexadecimal literal" ,
218
220
pair. as_span ( ) . start_pos ( ) ,
219
221
) ?;
220
- return Self :: from_str_radix ( text, 16 ) ;
222
+ Self :: from_str_radix ( text, 16 )
221
223
} else if t. starts_with ( "0b" ) || t. starts_with ( "0B" ) {
222
224
// Binary integer.
223
225
Self :: syntax_error (
@@ -389,10 +391,10 @@ impl Relax {
389
391
pair. as_span ( ) . start_pos ( ) ,
390
392
) ?;
391
393
let c = c. strip_suffix ( "*/" ) . unwrap ( ) . trim_end ( ) ;
392
- let lines = c. split ( " \n " ) . map ( str:: trim) . collect :: < Vec < _ > > ( ) ;
394
+ let lines = c. split ( '\n' ) . map ( str:: trim) . collect :: < Vec < _ > > ( ) ;
393
395
let lines = Self :: strip_leading_prefix ( & lines, '*' ) ;
394
396
let lines = Self :: strip_leading_prefix ( & lines, ' ' ) ;
395
- let start = if lines. get ( 0 ) . map ( |s| s. is_empty ( ) ) == Some ( true ) {
397
+ let start = if lines. first ( ) . map ( |s| s. is_empty ( ) ) == Some ( true ) {
396
398
1
397
399
} else {
398
400
0
@@ -405,7 +407,7 @@ impl Relax {
405
407
"slash comment" ,
406
408
pair. as_span ( ) . start_pos ( ) ,
407
409
) ?;
408
- let lines = comment. split ( " \n " ) . map ( str:: trim) . collect :: < Vec < _ > > ( ) ;
410
+ let lines = comment. split ( '\n' ) . map ( str:: trim) . collect :: < Vec < _ > > ( ) ;
409
411
let lines = Self :: strip_leading_prefix ( & lines, '/' ) ;
410
412
let lines = Self :: strip_leading_prefix ( & lines, ' ' ) ;
411
413
let end = lines. len ( )
@@ -416,13 +418,13 @@ impl Relax {
416
418
} ;
417
419
let c = lines[ ..end] . join ( "\n " ) ;
418
420
Ok ( Document :: Comment ( c, CommentFormat :: SlashSlash ) )
419
- } else if comment. starts_with ( "#" ) {
421
+ } else if comment. starts_with ( '#' ) {
420
422
Self :: syntax_error (
421
423
!self . comment_hash ,
422
424
"hash comment" ,
423
425
pair. as_span ( ) . start_pos ( ) ,
424
426
) ?;
425
- let lines = comment. split ( " \n " ) . map ( str:: trim) . collect :: < Vec < _ > > ( ) ;
427
+ let lines = comment. split ( '\n' ) . map ( str:: trim) . collect :: < Vec < _ > > ( ) ;
426
428
let lines = Self :: strip_leading_prefix ( & lines, '#' ) ;
427
429
let lines = Self :: strip_leading_prefix ( & lines, ' ' ) ;
428
430
let end = lines. len ( )
@@ -463,7 +465,7 @@ impl Relax {
463
465
Ok ( Document :: String ( value. join ( "\n " ) , StrFormat :: Multiline ) )
464
466
} else if s. starts_with ( '\'' ) || s. starts_with ( '"' ) {
465
467
Self :: syntax_error (
466
- !self . string_single_quote && s. starts_with ( "'" ) ,
468
+ !self . string_single_quote && s. starts_with ( '\'' ) ,
467
469
"single quote" ,
468
470
pair. as_span ( ) . start_pos ( ) ,
469
471
) ?;
@@ -595,7 +597,7 @@ impl Relax {
595
597
}
596
598
}
597
599
598
- _ => Err ( Error :: Unknown ( format ! ( "{:?}" , pair) ) . into ( ) ) ,
600
+ _ => Err ( Error :: Unknown ( format ! ( "{:?}" , pair) ) ) ,
599
601
}
600
602
}
601
603
}
@@ -723,7 +725,7 @@ mod tests {
723
725
}
724
726
}
725
727
726
- fn kv_extract < ' a > ( kv : Option < & ' a Document > ) -> Result < ( & ' a str , & ' a str ) > {
728
+ fn kv_extract ( kv : Option < & Document > ) -> Result < ( & str , & str ) > {
727
729
if let Some ( ( Document :: String ( k, _) , Document :: String ( v, _) ) ) =
728
730
kv. map ( Document :: as_kv) . transpose ( ) ?
729
731
{
0 commit comments