diff --git a/src/de.rs b/src/de.rs index d6cb502da..5b64138d8 100644 --- a/src/de.rs +++ b/src/de.rs @@ -1930,30 +1930,26 @@ impl<'de, 'a, R: Read<'de> + 'a> de::SeqAccess<'de> for SeqAccess<'a, R> { seq: &mut SeqAccess<'a, R>, ) -> Result { let peek = match tri!(seq.de.parse_whitespace()) { - Some(b']') => { - return Ok(false); - } - Some(b',') if !seq.first => { - seq.de.eat_char(); - tri!(seq.de.parse_whitespace()) - } - Some(b) => { - if seq.first { - seq.first = false; - Some(b) - } else { - return Err(seq.de.peek_error(ErrorCode::ExpectedListCommaOrEnd)); - } - } + Some(b) => b, None => { return Err(seq.de.peek_error(ErrorCode::EofWhileParsingList)); } }; - match peek { - Some(b']') => Err(seq.de.peek_error(ErrorCode::TrailingComma)), - Some(_) => Ok(true), - None => Err(seq.de.peek_error(ErrorCode::EofWhileParsingValue)), + if peek == b']' { + Ok(false) + } else if seq.first { + seq.first = false; + Ok(true) + } else if peek == b',' { + seq.de.eat_char(); + match tri!(seq.de.parse_whitespace()) { + Some(b']') => Err(seq.de.peek_error(ErrorCode::TrailingComma)), + Some(_) => Ok(true), + None => Err(seq.de.peek_error(ErrorCode::EofWhileParsingValue)), + } + } else { + Err(seq.de.peek_error(ErrorCode::ExpectedListCommaOrEnd)) } } @@ -1985,31 +1981,31 @@ impl<'de, 'a, R: Read<'de> + 'a> de::MapAccess<'de> for MapAccess<'a, R> { { fn has_next_key<'de, 'a, R: Read<'de> + 'a>(map: &mut MapAccess<'a, R>) -> Result { let peek = match tri!(map.de.parse_whitespace()) { - Some(b'}') => { - return Ok(false); - } - Some(b',') if !map.first => { - map.de.eat_char(); - tri!(map.de.parse_whitespace()) - } - Some(b) => { - if map.first { - map.first = false; - Some(b) - } else { - return Err(map.de.peek_error(ErrorCode::ExpectedObjectCommaOrEnd)); - } - } + Some(b) => b, None => { return Err(map.de.peek_error(ErrorCode::EofWhileParsingObject)); } }; - match peek { - Some(b'"') => Ok(true), - Some(b'}') => Err(map.de.peek_error(ErrorCode::TrailingComma)), - Some(_) => Err(map.de.peek_error(ErrorCode::KeyMustBeAString)), - None => Err(map.de.peek_error(ErrorCode::EofWhileParsingValue)), + if peek == b'}' { + Ok(false) + } else if map.first { + map.first = false; + if peek == b'"' { + Ok(true) + } else { + Err(map.de.peek_error(ErrorCode::KeyMustBeAString)) + } + } else if peek == b',' { + map.de.eat_char(); + match tri!(map.de.parse_whitespace()) { + Some(b'"') => Ok(true), + Some(b'}') => Err(map.de.peek_error(ErrorCode::TrailingComma)), + Some(_) => Err(map.de.peek_error(ErrorCode::KeyMustBeAString)), + None => Err(map.de.peek_error(ErrorCode::EofWhileParsingValue)), + } + } else { + Err(map.de.peek_error(ErrorCode::ExpectedObjectCommaOrEnd)) } }