@@ -53,7 +53,7 @@ pub enum TrailingComma {
53
53
NONE
54
54
}
55
55
56
- pub struct StyleConfiguration {
56
+ pub struct FormatConfiguration {
57
57
pub ( crate ) indent : Option < usize > ,
58
58
pub ( crate ) item_separator : String ,
59
59
pub ( crate ) key_separator : String ,
@@ -62,33 +62,32 @@ pub struct StyleConfiguration {
62
62
}
63
63
64
64
#[ allow( dead_code) ]
65
- impl StyleConfiguration {
65
+ impl FormatConfiguration {
66
66
pub fn new ( indent : Option < usize > , item_separator : & str , key_separator : & str , trailing_comma : TrailingComma ) -> Self {
67
- StyleConfiguration { indent : indent, item_separator : item_separator. to_string ( ) , key_separator : key_separator. to_string ( ) , current_indent : String :: with_capacity ( 64 ) , trailing_comma : trailing_comma}
67
+ FormatConfiguration { indent : indent, item_separator : item_separator. to_string ( ) , key_separator : key_separator. to_string ( ) , current_indent : String :: with_capacity ( 64 ) , trailing_comma : trailing_comma}
68
68
}
69
69
70
70
pub fn with_indent ( indent : usize , trailing_comma : TrailingComma ) -> Self {
71
- StyleConfiguration { indent : Some ( indent) , item_separator : "," . to_string ( ) , key_separator : ": " . to_string ( ) , trailing_comma, current_indent : String :: with_capacity ( 64 ) }
71
+ FormatConfiguration { indent : Some ( indent) , item_separator : "," . to_string ( ) , key_separator : ": " . to_string ( ) , trailing_comma, current_indent : String :: with_capacity ( 64 ) }
72
72
}
73
73
74
74
pub fn with_separators ( item_separator : & str , key_separator : & str , trailing_comma : TrailingComma ) -> Self {
75
- StyleConfiguration { indent : Some ( 0 ) , key_separator : key_separator. to_string ( ) , trailing_comma, item_separator : item_separator. to_string ( ) , current_indent : String :: with_capacity ( 64 ) }
75
+ FormatConfiguration { indent : Some ( 0 ) , key_separator : key_separator. to_string ( ) , trailing_comma, item_separator : item_separator. to_string ( ) , current_indent : String :: with_capacity ( 64 ) }
76
76
}
77
77
78
78
pub fn default ( ) -> Self {
79
- StyleConfiguration { indent : None , item_separator : ", " . to_string ( ) , key_separator : ": " . to_string ( ) , current_indent : String :: with_capacity ( 64 ) , trailing_comma : TrailingComma :: NONE }
80
-
79
+ FormatConfiguration { indent : None , item_separator : ", " . to_string ( ) , key_separator : ": " . to_string ( ) , current_indent : String :: with_capacity ( 64 ) , trailing_comma : TrailingComma :: NONE }
81
80
}
82
81
}
83
82
84
83
impl < ' input > JSONKeyValuePair < ' input > {
85
- fn to_string_styled ( & self , style : & mut StyleConfiguration ) -> String {
86
- format ! ( "{}{}{}" , self . key. to_string_styled ( style) , style. key_separator, self . value)
84
+ fn to_string_formatted ( & self , style : & mut FormatConfiguration ) -> String {
85
+ format ! ( "{}{}{}" , self . key. to_string_formatted ( style) , style. key_separator, self . value)
87
86
}
88
87
}
89
88
90
89
impl < ' input > JSONValue < ' input > {
91
- fn to_string_styled ( & self , style : & mut StyleConfiguration ) -> String {
90
+ fn to_string_formatted ( & self , style : & mut FormatConfiguration ) -> String {
92
91
match self {
93
92
JSONValue :: Identifier ( s) | JSONValue :: Integer ( s) | JSONValue :: Float ( s) | JSONValue :: Exponent ( s) | JSONValue :: Hexadecimal ( s) => {
94
93
format ! ( "{}" , s)
@@ -131,7 +130,7 @@ impl<'input> JSONValue<'input> {
131
130
}
132
131
}
133
132
for ( idx, kvp) in key_value_pairs. iter ( ) . enumerate ( ) {
134
- ret. push_str ( kvp. to_string_styled ( style) . as_str ( ) ) ;
133
+ ret. push_str ( kvp. to_string_formatted ( style) . as_str ( ) ) ;
135
134
if idx < key_value_pairs. len ( ) - 1 {
136
135
match style. indent {
137
136
None => {
@@ -176,7 +175,7 @@ impl<'input> JSONValue<'input> {
176
175
}
177
176
}
178
177
for ( idx, value) in values. iter ( ) . enumerate ( ) {
179
- ret. push_str ( value. to_string_styled ( style) . as_str ( ) ) ;
178
+ ret. push_str ( value. to_string_formatted ( style) . as_str ( ) ) ;
180
179
if idx < values. len ( ) - 1 {
181
180
match style. indent {
182
181
None => {
@@ -212,16 +211,16 @@ impl<'input> JSONValue<'input> {
212
211
213
212
impl < ' input > Display for JSONValue < ' input > {
214
213
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
215
- let mut style = StyleConfiguration :: default ( ) ;
216
- let res = self . to_string_styled ( & mut style) ;
214
+ let mut style = FormatConfiguration :: default ( ) ;
215
+ let res = self . to_string_formatted ( & mut style) ;
217
216
write ! ( f, "{}" , res)
218
217
}
219
218
}
220
219
221
220
222
221
impl < ' input > Display for JSONText < ' input > {
223
222
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
224
- write ! ( f, "{}" , self . value. to_string_styled ( & mut StyleConfiguration :: default ( ) ) )
223
+ write ! ( f, "{}" , self . value. to_string_formatted ( & mut FormatConfiguration :: default ( ) ) )
225
224
}
226
225
}
227
226
0 commit comments