Skip to content

Commit ad9bcf0

Browse files
committed
clippy fixes
1 parent 657ab05 commit ad9bcf0

File tree

7 files changed

+172
-228
lines changed

7 files changed

+172
-228
lines changed

src/de.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub enum SerdeJSON5Error {
1111
impl fmt::Display for SerdeJSON5Error {
1212
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1313
match self {
14-
SerdeJSON5Error::Custom(msg) => write!(f, "{}", msg),
14+
SerdeJSON5Error::Custom(msg) => write!(f, "{msg}"),
1515
}
1616
}
1717
}
@@ -71,7 +71,7 @@ impl<'de, 'a> Deserializer<'de> for JSONValueDeserializer<'a> {
7171
visitor.visit_u64(u)
7272
} else {
7373
// fallback: treat as a string or produce an error
74-
Err(de::Error::custom(format!("Invalid integer literal: {}", s)))
74+
Err(de::Error::custom(format!("Invalid integer literal: {s}")))
7575
}
7676
}
7777
}
@@ -80,7 +80,7 @@ impl<'de, 'a> Deserializer<'de> for JSONValueDeserializer<'a> {
8080
if let Ok(f) = s.parse::<f64>() {
8181
visitor.visit_f64(f)
8282
} else {
83-
Err(de::Error::custom(format!("Invalid float {}", s)))
83+
Err(de::Error::custom(format!("Invalid float {s}")))
8484
}
8585
}
8686
JSONValue::Infinity => visitor.visit_f64(f64::INFINITY),
@@ -92,7 +92,7 @@ impl<'de, 'a> Deserializer<'de> for JSONValueDeserializer<'a> {
9292
visitor.visit_u64(hex)
9393
}
9494
Err(e) => {
95-
Err(de::Error::custom(format!("Invalid hex {}", e)))
95+
Err(de::Error::custom(format!("Invalid hex {e}")))
9696
}
9797
}
9898
}
@@ -111,7 +111,7 @@ impl<'de, 'a> Deserializer<'de> for JSONValueDeserializer<'a> {
111111
visitor.visit_u64(x)
112112
}
113113
_ => {
114-
Err(de::Error::custom(format!("Invalid integer literal for unary: {:?}", s)))
114+
Err(de::Error::custom(format!("Invalid integer literal for unary: {s:?}")))
115115

116116
}
117117
}
@@ -124,7 +124,7 @@ impl<'de, 'a> Deserializer<'de> for JSONValueDeserializer<'a> {
124124
UnaryOperator::Minus => {visitor.visit_f64(f.neg())}
125125
}
126126
} else {
127-
Err(de::Error::custom(format!("Invalid float literal: {:?}", s)))
127+
Err(de::Error::custom(format!("Invalid float literal: {s:?}")))
128128
}
129129
}
130130
JSONValue::Infinity => {
@@ -148,20 +148,20 @@ impl<'de, 'a> Deserializer<'de> for JSONValueDeserializer<'a> {
148148
}
149149
UnaryOperator::Minus => {
150150
if hex > i64::MAX as u64 {
151-
return Err(de::Error::custom(format!("Overflow when converting {} to i64", s)))
151+
return Err(de::Error::custom(format!("Overflow when converting {s} to i64")))
152152
}
153153
let i = hex as i64;
154154
visitor.visit_i64(i)
155155
}
156156
}
157157
}
158158
Err(e) => {
159-
Err(de::Error::custom(format!("Invalid hex {}", e)))
159+
Err(de::Error::custom(format!("Invalid hex {e}")))
160160
}
161161
}
162162
}
163163
invalid_unary_val => {
164-
Err(de::Error::custom(format!("Invalid unary value: {:?}", invalid_unary_val)))
164+
Err(de::Error::custom(format!("Invalid unary value: {invalid_unary_val:?}")))
165165
}
166166
}
167167
}
@@ -213,13 +213,13 @@ impl<'de, 'a> Deserializer<'de> for JSONValueDeserializer<'a> {
213213
match u64::from_str_radix(s.to_lowercase().trim_start_matches("0x"), 16) {
214214
Ok(hex) => {
215215
if hex > i64::MAX as u64 {
216-
return Err(de::Error::custom(format!("Overflow when converting {} to i64", s)))
216+
return Err(de::Error::custom(format!("Overflow when converting {s} to i64")))
217217
}
218218
let i = hex as i64;
219219
visitor.visit_i64(i)
220220
}
221221
Err(e) => {
222-
Err(de::Error::custom(format!("Invalid hex {}", e)))
222+
Err(de::Error::custom(format!("Invalid hex {e}")))
223223
}
224224
}
225225
}
@@ -236,7 +236,7 @@ impl<'de, 'a> Deserializer<'de> for JSONValueDeserializer<'a> {
236236
match u64::from_str_radix(s.to_lowercase().trim_start_matches("0x"), 16) {
237237
Ok(hex) => {
238238
if hex > i64::MAX as u64 {
239-
return Err(de::Error::custom(format!("Overflow when converting {} to i64", s)))
239+
return Err(de::Error::custom(format!("Overflow when converting {s} to i64")))
240240
}
241241
let i = hex as i64;
242242
match operator {
@@ -249,12 +249,12 @@ impl<'de, 'a> Deserializer<'de> for JSONValueDeserializer<'a> {
249249
}
250250
}
251251
Err(e) => {
252-
Err(de::Error::custom(format!("Invalid hex {}", e)))
252+
Err(de::Error::custom(format!("Invalid hex {e}")))
253253
}
254254
}
255255
}
256256
val => {
257-
Err(de::Error::custom(format!("Unsupported value for i64 {:?}", val)))
257+
Err(de::Error::custom(format!("Unsupported value for i64 {val:?}")))
258258
}
259259
}
260260
}
@@ -298,7 +298,7 @@ impl<'de, 'a> Deserializer<'de> for JSONValueDeserializer<'a> {
298298
visitor.visit_u64(hex)
299299
}
300300
Err(e) => {
301-
Err(de::Error::custom(format!("Invalid hex {}", e)))
301+
Err(de::Error::custom(format!("Invalid hex {e}")))
302302
}
303303
}
304304
}
@@ -310,7 +310,7 @@ impl<'de, 'a> Deserializer<'de> for JSONValueDeserializer<'a> {
310310
UnaryOperator::Plus => {visitor.visit_u64(i)}
311311
UnaryOperator::Minus => {
312312
if i != 0 {
313-
Err(de::Error::custom(format!("Invalid integer value: {:?}", s)))
313+
Err(de::Error::custom(format!("Invalid integer value: {s:?}")))
314314
} else {
315315
visitor.visit_u64(0)
316316
}
@@ -326,7 +326,7 @@ impl<'de, 'a> Deserializer<'de> for JSONValueDeserializer<'a> {
326326
}
327327
UnaryOperator::Minus => {
328328
if hex != 0 {
329-
Err(de::Error::custom(format!("Invalid integer value: {:?}", s)))
329+
Err(de::Error::custom(format!("Invalid integer value: {s:?}")))
330330
} else {
331331
visitor.visit_u64(0)
332332
}
@@ -335,12 +335,12 @@ impl<'de, 'a> Deserializer<'de> for JSONValueDeserializer<'a> {
335335
}
336336
}
337337
Err(e) => {
338-
Err(de::Error::custom(format!("Invalid hex {}", e)))
338+
Err(de::Error::custom(format!("Invalid hex {e}")))
339339
}
340340
}
341341
}
342342
val => {
343-
Err(de::Error::custom(format!("Unsupported value for u64 {:?}", val)))
343+
Err(de::Error::custom(format!("Unsupported value for u64 {val:?}")))
344344
}
345345
}
346346
}

src/parser.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub struct FormatConfiguration {
6464
#[allow(dead_code)]
6565
impl FormatConfiguration {
6666
pub fn new(indent: Option<usize>, item_separator: &str, key_separator: &str, trailing_comma: TrailingComma) -> Self {
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}
67+
FormatConfiguration {indent, item_separator: item_separator.to_string(), key_separator: key_separator.to_string(), current_indent: String::with_capacity(64), trailing_comma}
6868
}
6969

7070
pub fn with_indent(indent: usize, trailing_comma: TrailingComma) -> Self {
@@ -94,16 +94,16 @@ impl<'input> JSONValue<'input> {
9494
fn to_string_formatted(&self, style: &mut FormatConfiguration) -> String {
9595
match self {
9696
JSONValue::Identifier(s) | JSONValue::Integer(s) | JSONValue::Float(s) | JSONValue::Exponent(s) | JSONValue::Hexadecimal(s) => {
97-
format!("{}", s)
97+
s.to_string()
9898
}
9999
JSONValue::Bool(b) => {
100-
format!("{}", b)
100+
format!("{b}")
101101
}
102102
JSONValue::DoubleQuotedString(s) => {
103-
format!("\"{}\"", s)
103+
format!("\"{s}\"")
104104
}
105105
JSONValue::SingleQuotedString(s) => {
106-
format!("'{}'", s)
106+
format!("'{s}'")
107107
}
108108

109109
JSONValue::Null => {"null".to_string()}
@@ -116,7 +116,7 @@ impl<'input> JSONValue<'input> {
116116
UnaryOperator::Minus => {'-'}
117117
};
118118
let value_string = value.to_string();
119-
format!("{}{}", op_char, value_string)
119+
format!("{op_char}{value_string}")
120120
}
121121
JSONValue::JSONObject { key_value_pairs} => {
122122
let mut ret: String;
@@ -154,7 +154,7 @@ impl<'input> JSONValue<'input> {
154154
}
155155
match style.indent {
156156
None => {
157-
ret.push_str("}");
157+
ret.push('}');
158158
}
159159
Some(ident) => {
160160
style.current_indent.truncate(style.current_indent.len() - ident);
@@ -199,7 +199,7 @@ impl<'input> JSONValue<'input> {
199199
}
200200
match style.indent {
201201
None => {
202-
ret.push_str("]");
202+
ret.push(']');
203203
}
204204
Some(ident) => {
205205
style.current_indent.truncate(style.current_indent.len() - ident);
@@ -217,7 +217,7 @@ impl<'input> Display for JSONValue<'input> {
217217
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
218218
let mut style = FormatConfiguration::default();
219219
let res = self.to_string_formatted(&mut style);
220-
write!(f, "{}", res)
220+
write!(f, "{res}")
221221
}
222222
}
223223

@@ -263,7 +263,7 @@ impl<'toks, 'input> JSON5Parser<'toks, 'input> {
263263
}
264264

265265
fn with_max_depth(tokens: &'toks Tokens<'input>, max_depth: usize) -> Self {
266-
JSON5Parser { source_tokens: tokens.tok_spans.iter().peekable(), lookahead: None, source: tokens.source, current_depth: 0, max_depth: max_depth }
266+
JSON5Parser { source_tokens: tokens.tok_spans.iter().peekable(), lookahead: None, source: tokens.source, current_depth: 0, max_depth }
267267
}
268268

269269
fn advance(&mut self) -> Option<&'toks TokenSpan> {
@@ -275,7 +275,7 @@ impl<'toks, 'input> JSON5Parser<'toks, 'input> {
275275
Some(span) => {
276276
match span.1 {
277277
TokType::BlockComment | TokType::LineComment | TokType::Whitespace => {
278-
return self.advance()
278+
self.advance()
279279
}
280280
_ => {
281281

@@ -400,7 +400,7 @@ impl<'toks, 'input> JSON5Parser<'toks, 'input> {
400400
}
401401
Some(_) => {
402402
let val = self.parse_value()?;
403-
let kvp = JSONKeyValuePair{key: key, value: val};
403+
let kvp = JSONKeyValuePair{key, value: val};
404404
kvps.push(kvp);
405405
match self.check_and_consume(vec![Comma]) {
406406
None => {
@@ -444,7 +444,7 @@ impl<'toks, 'input> JSON5Parser<'toks, 'input> {
444444
return Err(self.make_error("Expecting ']' at end of array".to_string(), idx))
445445
},
446446
Some(_) => {
447-
break Ok(JSONValue::JSONArray {values: values})
447+
break Ok(JSONValue::JSONArray {values})
448448
}
449449
}
450450
}
@@ -454,7 +454,7 @@ impl<'toks, 'input> JSON5Parser<'toks, 'input> {
454454
}
455455
}
456456
Some(_) => {
457-
break Ok(JSONValue::JSONArray {values: values})
457+
break Ok(JSONValue::JSONArray {values})
458458
}
459459
}
460460
}
@@ -501,7 +501,7 @@ impl<'toks, 'input> JSON5Parser<'toks, 'input> {
501501
return Err(self.make_error("Only one unary operator is allowed".to_string(), span.2))
502502
}
503503
val => {
504-
return Err(self.make_error(format!("Unary operations not allowed for value {:?}", val), span.2))
504+
return Err(self.make_error(format!("Unary operations not allowed for value {val:?}"), span.2))
505505
}
506506
}
507507
match span.1 {
@@ -532,13 +532,13 @@ impl<'toks, 'input> JSON5Parser<'toks, 'input> {
532532

533533

534534
fn parse_value(&mut self) -> Result<JSONValue<'input>, ParsingError> {
535-
self.current_depth = self.current_depth + 1;
535+
self.current_depth += 1;
536536
if self.current_depth > self.max_depth {
537537
let idx = self.position();
538538
return Err(self.make_error(format!("max depth ({}) exceeded in nested arrays/objects. To expand the depth, use the ``with_max_depth`` constructor or enable the `unlimited_depth` feature", self.max_depth), idx))
539539
}
540540
let res = self.parse_obj_or_array();
541-
self.current_depth = self.current_depth - 1;
541+
self.current_depth -= 1;
542542
res
543543
}
544544

@@ -558,7 +558,7 @@ impl<'toks, 'input> JSON5Parser<'toks, 'input> {
558558

559559

560560
/// Like [from_str] but for [Tokens]
561-
pub fn from_tokens<'toks, 'input>(tokens: &'toks Tokens<'input>) -> Result<JSONText<'input>, ParsingError> {
561+
pub fn from_tokens<'input>(tokens: &Tokens<'input>) -> Result<JSONText<'input>, ParsingError> {
562562
let mut parser = JSON5Parser::new(tokens);
563563
parser.parse_text()
564564
}

0 commit comments

Comments
 (0)