clippy
diff --git a/src/de.rs b/src/de.rs
index 4cd2641..8596f3a 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -1,4 +1,4 @@
-use pest::iterators::{Pair, Pairs};
+use pest::iterators::Pair;
use pest::Parser as P;
use pest_derive::Parser;
use serde::de;
@@ -264,7 +264,7 @@
s if is_hex_literal(s) => Ok(parse_hex(&s[2..])? as i64),
s => s
.parse()
- .or(Err(de::Error::custom("error parsing integer"))),
+ .or_else(|_| Err(de::Error::custom("error parsing integer"))),
}
}
@@ -273,7 +273,7 @@
}
fn parse_hex(s: &str) -> Result<u32> {
- u32::from_str_radix(s, 16).or(Err(de::Error::custom("error parsing hex")))
+ u32::from_str_radix(s, 16).or_else(|_| Err(de::Error::custom("error parsing hex")))
}
fn is_hex_literal(s: &str) -> bool {
@@ -287,7 +287,7 @@
impl<'de> Seq<'de> {
pub fn new(pair: Pair<'de, Rule>) -> Self {
Self {
- pairs: pair.into_inner().into_iter().collect(),
+ pairs: pair.into_inner().collect(),
}
}
}
@@ -319,7 +319,7 @@
impl<'de> Map<'de> {
pub fn new(pair: Pair<'de, Rule>) -> Self {
Self {
- pairs: pair.into_inner().into_iter().collect(),
+ pairs: pair.into_inner().collect(),
}
}
}
diff --git a/src/error.rs b/src/error.rs
index 7338edb..4399ea0 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,4 +1,3 @@
-use pest;
use serde::{de, ser};
use std::fmt::{self, Display};
diff --git a/src/lib.rs b/src/lib.rs
index 8430107..68d3e51 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -36,25 +36,23 @@
//! n: i32,
//! }
//!
-//! fn main() {
-//! let config = "
-//! {
-//! // A traditional message.
-//! message: 'hello world',
+//! let config = "
+//! {
+//! // A traditional message.
+//! message: 'hello world',
//!
-//! // A number for some reason.
-//! n: 42,
-//! }
-//! ";
+//! // A number for some reason.
+//! n: 42,
+//! }
+//! ";
//!
-//! assert_eq!(
-//! json5::from_str(config),
-//! Ok(Config {
-//! message: "hello world".to_string(),
-//! n: 42,
-//! }),
-//! );
-//! }
+//! assert_eq!(
+//! json5::from_str(config),
+//! Ok(Config {
+//! message: "hello world".to_string(),
+//! n: 42,
+//! }),
+//! );
//! ```
//!
//! There are many ways to customise the deserialization (e.g. deserializing `camelCase` field
@@ -79,16 +77,14 @@
//! String(String),
//! }
//!
-//! fn main() {
-//! assert_eq!(
-//! json5::to_string(&vec![
-//! Val::Number(42.),
-//! Val::Bool(true),
-//! Val::String("hello".to_owned()),
-//! ]),
-//! Ok("[42,true,\"hello\"]".to_owned()),
-//! )
-//! }
+//! assert_eq!(
+//! json5::to_string(&vec![
+//! Val::Number(42.),
+//! Val::Bool(true),
+//! Val::String("hello".to_owned()),
+//! ]),
+//! Ok("[42,true,\"hello\"]".to_owned()),
+//! )
//! ```
//!
//! There are many ways to customise the serialization (e.g. serializing `snake_case` struct fields
diff --git a/src/ser.rs b/src/ser.rs
index 6d8b1f0..6e271fc 100644
--- a/src/ser.rs
+++ b/src/ser.rs
@@ -79,27 +79,29 @@
}
fn serialize_f32(self, v: f32) -> Result<()> {
- Ok(if v == f32::INFINITY {
+ if v == f32::INFINITY {
self.output += "Infinity";
} else if v == f32::NEG_INFINITY {
self.output += "-Infinity";
- } else if v == f32::NAN {
+ } else if v.is_nan() {
self.output += "NaN";
} else {
self.call_to_string(&v)?;
- })
+ }
+ Ok(())
}
fn serialize_f64(self, v: f64) -> Result<()> {
- Ok(if v == f64::INFINITY {
+ if v == f64::INFINITY {
self.output += "Infinity";
} else if v == f64::NEG_INFINITY {
self.output += "-Infinity";
- } else if v == f64::NAN {
+ } else if v.is_nan() {
self.output += "NaN";
} else {
self.call_to_string(&v)?;
- })
+ }
+ Ok(())
}
fn serialize_char(self, v: char) -> Result<()> {