From e3976358fd767248015c4bc7d4edecd4db4df7ac Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 30 Mar 2017 12:38:48 +0100 Subject: Remove unneeded return statements --- src/de.rs | 6 +++--- src/tokens.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/de.rs b/src/de.rs index 42cf86c..9b6a779 100644 --- a/src/de.rs +++ b/src/de.rs @@ -38,7 +38,7 @@ pub fn from_str(s: &str) -> Result let mut d = Deserializer::new(s); let ret = T::deserialize(&mut d)?; d.end()?; - return Ok(ret) + Ok(ret) } /// Errors that can occur when deserializing a type. @@ -357,7 +357,7 @@ impl<'a, 'b> de::SeqVisitor for MapVisitor<'a, 'b> { de: &mut self.de, })?; self.cur_parent = next; - return Ok(Some(ret)) + Ok(Some(ret)) } } @@ -1003,7 +1003,7 @@ impl<'a> Deserializer<'a> { let (line, col) = self.to_linecol(at); err.inner.line = Some(line); err.inner.col = col; - return err + err } /// Converts a byte offset from an error message to a (line, column) pair diff --git a/src/tokens.rs b/src/tokens.rs index ec7bb08..f438fed 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -66,7 +66,7 @@ impl<'a> Tokenizer<'a> { }; // Eat utf-8 BOM t.eatc('\u{feff}'); - return t + t } pub fn next(&mut self) -> Result>, Error> { -- cgit v1.2.3 From 635e742488c076fb646efb86e182ffa9ff8fe73d Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 30 Mar 2017 12:39:46 +0100 Subject: Switch from comparison to is_empty() --- src/de.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/de.rs b/src/de.rs index 9b6a779..0888186 100644 --- a/src/de.rs +++ b/src/de.rs @@ -148,7 +148,7 @@ impl<'a, 'b> de::Deserializer for &'b mut Deserializer<'a> { while let Some(line) = self.line()? { match line { Line::Table { at, mut header, array } => { - if cur_table.header.len() > 0 || cur_table.values.is_some() { + if !cur_table.header.is_empty() || cur_table.values.is_some() { tables.push(cur_table); } cur_table = Table { @@ -175,7 +175,7 @@ impl<'a, 'b> de::Deserializer for &'b mut Deserializer<'a> { } } } - if cur_table.header.len() > 0 || cur_table.values.is_some() { + if !cur_table.header.is_empty() || cur_table.values.is_some() { tables.push(cur_table); } @@ -1095,7 +1095,7 @@ impl fmt::Display for Error { ErrorKind::__Nonexhaustive => panic!(), } - if self.inner.key.len() > 0 { + if !self.inner.key.is_empty() { write!(f, " for key `")?; for (i, k) in self.inner.key.iter().enumerate() { if i > 0 { -- cgit v1.2.3 From a2053c850515a0d9f45cd0a3cec9acc555117e87 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 30 Mar 2017 12:40:27 +0100 Subject: Simplify if-statements --- src/datetime.rs | 7 +++---- src/de.rs | 10 +++++----- src/ser.rs | 2 +- src/tokens.rs | 2 +- tests/valid.rs | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/datetime.rs b/src/datetime.rs index 7a618dc..b3c82d6 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -179,11 +179,10 @@ impl FromStr for Datetime { chars.clone().next() == Some('T') { chars.next(); true - } else if full_date.is_none() { - true } else { - false + full_date.is_none() }; + let time = if partial_time { let h1 = digit(&mut chars)?; let h2 = digit(&mut chars)?; @@ -299,7 +298,7 @@ impl FromStr for Datetime { fn digit(chars: &mut str::Chars) -> Result { match chars.next() { - Some(c) if '0' <= c && c <= '9' => Ok(c as u8 - '0' as u8), + Some(c) if '0' <= c && c <= '9' => Ok(c as u8 - b'0'), _ => Err(DatetimeParseError { _private: () }), } } diff --git a/src/de.rs b/src/de.rs index 0888186..0022791 100644 --- a/src/de.rs +++ b/src/de.rs @@ -687,7 +687,7 @@ impl<'a> Deserializer<'a> { } fn number_or_date(&mut self, s: &'a str) -> Result, Error> { - if s.contains("T") || (s.len() > 1 && s[1..].contains("-")) && + if s.contains('T') || (s.len() > 1 && s[1..].contains('-')) && !s.contains("e-") { self.datetime(s, false).map(Value::Datetime) } else if self.eat(Token::Colon)? { @@ -698,7 +698,7 @@ impl<'a> Deserializer<'a> { } fn number(&mut self, s: &'a str) -> Result, Error> { - if s.contains("e") || s.contains("E") { + if s.contains('e') || s.contains('E') { self.float(s, None).map(Value::Float) } else if self.eat(Token::Period)? { let at = self.tokens.current(); @@ -727,7 +727,7 @@ impl<'a> Deserializer<'a> { if suffix != "" { return Err(self.error(start, ErrorKind::NumberInvalid)) } - prefix.replace("_", "").trim_left_matches("+").parse().map_err(|_e| { + prefix.replace("_", "").trim_left_matches('+').parse().map_err(|_e| { self.error(start, ErrorKind::NumberInvalid) }) } @@ -789,7 +789,7 @@ impl<'a> Deserializer<'a> { } let mut exponent = None; - if suffix.starts_with("e") || suffix.starts_with("E") { + if suffix.starts_with('e') || suffix.starts_with('E') { let (a, b) = if suffix.len() == 1 { self.eat(Token::Plus)?; match self.next()? { @@ -807,7 +807,7 @@ impl<'a> Deserializer<'a> { exponent = Some(a); } - let mut number = integral.trim_left_matches("+") + let mut number = integral.trim_left_matches('+') .chars() .filter(|c| *c != '_') .collect::(); diff --git a/src/ser.rs b/src/ser.rs index 0b9308d..bc5f357 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -563,7 +563,7 @@ impl<'a, 'b> ser::SerializeMap for SerializeTable<'a, 'b> { SerializeTable::Table { ref mut key, .. } => { key.truncate(0); *key = input.serialize(StringExtractor)?; - if key.contains("\n") { + if key.contains('\n') { return Err(Error::KeyNewline) } } diff --git a/src/tokens.rs b/src/tokens.rs index f438fed..6b7c3bc 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -141,7 +141,7 @@ impl<'a> Tokenizer<'a> { if val == "" { return Err(Error::EmptyTableKey(offset)) } - match src.find("\n") { + match src.find('\n') { None => Ok(val), Some(i) => Err(Error::NewlineInTableKey(offset + i)), } diff --git a/tests/valid.rs b/tests/valid.rs index 4229f1c..e8ea6af 100644 --- a/tests/valid.rs +++ b/tests/valid.rs @@ -18,7 +18,7 @@ fn to_json(toml: toml::Value) -> Json { Toml::Float(f) => doit("float", Json::String({ let s = format!("{:.15}", f); let s = format!("{}", s.trim_right_matches('0')); - if s.ends_with(".") {format!("{}0", s)} else {s} + if s.ends_with('.') {format!("{}0", s)} else {s} })), Toml::Boolean(b) => doit("bool", Json::String(format!("{}", b))), Toml::Datetime(s) => doit("datetime", Json::String(s.to_string())), -- cgit v1.2.3 From d1558f78efff59b167f4ce264b18534b125f697a Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 30 Mar 2017 12:42:27 +0100 Subject: Stop taking references when not needed --- src/de.rs | 4 ++-- src/ser.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/de.rs b/src/de.rs index 0022791..13a3d90 100644 --- a/src/de.rs +++ b/src/de.rs @@ -470,7 +470,7 @@ impl<'a> de::Deserializer for ValueDeserializer<'a> { where V: de::Visitor, { if name == SERDE_STRUCT_NAME && fields == &[SERDE_STRUCT_FIELD_NAME] { - if let Value::Datetime(ref s) = self.value { + if let Value::Datetime(s) = self.value { return visitor.visit_map(DatetimeDeserializer { date: s, visited: false, @@ -783,7 +783,7 @@ impl<'a> Deserializer<'a> { if suffix != "" { return Err(self.error(start, ErrorKind::NumberInvalid)) } - let (a, b) = self.parse_integer(&after, false, true)?; + let (a, b) = self.parse_integer(after, false, true)?; fraction = Some(a); suffix = b; } diff --git a/src/ser.rs b/src/ser.rs index bc5f357..8fcf0eb 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -283,7 +283,7 @@ impl<'a> Serializer<'a> { if array_of_tables { self.dst.push_str("["); } - self.emit_key_part(&state)?; + self.emit_key_part(state)?; if array_of_tables { self.dst.push_str("]"); } @@ -586,10 +586,10 @@ impl<'a, 'b> ser::SerializeMap for SerializeTable<'a, 'b> { let res = value.serialize(&mut Serializer { dst: &mut *ser.dst, state: State::Table { - key: &key, + key: key, parent: &ser.state, - first: &first, - table_emitted: &table_emitted, + first: first, + table_emitted: table_emitted, }, }); match res { -- cgit v1.2.3 From e382b8d895e13b7cac6d35a905aa0490f3bb03d1 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 30 Mar 2017 12:42:35 +0100 Subject: Remove lifetimes --- src/tokens.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tokens.rs b/src/tokens.rs index 6b7c3bc..11f47f5 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -422,7 +422,7 @@ impl MaybeString { } } - fn into_cow<'a>(self, input: &'a str) -> Cow<'a, str> { + fn into_cow(self, input: &str) -> Cow { match self { MaybeString::NotEscaped(start) => Cow::Borrowed(&input[start..]), MaybeString::Owned(s) => Cow::Owned(s), -- cgit v1.2.3