Skip to content

Commit 2a4cb44

Browse files
committed
Rearrange 'match peek'
1 parent 4cb90ce commit 2a4cb44

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

src/de.rs

+26-34
Original file line numberDiff line numberDiff line change
@@ -1929,31 +1929,25 @@ impl<'de, 'a, R: Read<'de> + 'a> de::SeqAccess<'de> for SeqAccess<'a, R> {
19291929
fn has_next_element<'de, 'a, R: Read<'de> + 'a>(
19301930
seq: &mut SeqAccess<'a, R>,
19311931
) -> Result<bool> {
1932-
let peek = match tri!(seq.de.parse_whitespace()) {
1933-
Some(b']') => {
1934-
return Ok(false);
1935-
}
1932+
match tri!(seq.de.parse_whitespace()) {
1933+
Some(b']') => Ok(false),
19361934
Some(b',') if !seq.first => {
19371935
seq.de.eat_char();
1938-
tri!(seq.de.parse_whitespace())
1936+
match tri!(seq.de.parse_whitespace()) {
1937+
Some(b']') => Err(seq.de.peek_error(ErrorCode::TrailingComma)),
1938+
Some(_) => Ok(true),
1939+
None => Err(seq.de.peek_error(ErrorCode::EofWhileParsingValue)),
1940+
}
19391941
}
1940-
Some(b) => {
1942+
Some(_) => {
19411943
if seq.first {
19421944
seq.first = false;
1943-
Some(b)
1945+
Ok(true)
19441946
} else {
1945-
return Err(seq.de.peek_error(ErrorCode::ExpectedListCommaOrEnd));
1947+
Err(seq.de.peek_error(ErrorCode::ExpectedListCommaOrEnd))
19461948
}
19471949
}
1948-
None => {
1949-
return Err(seq.de.peek_error(ErrorCode::EofWhileParsingList));
1950-
}
1951-
};
1952-
1953-
match peek {
1954-
Some(b']') => Err(seq.de.peek_error(ErrorCode::TrailingComma)),
1955-
Some(_) => Ok(true),
1956-
None => Err(seq.de.peek_error(ErrorCode::EofWhileParsingValue)),
1950+
None => Err(seq.de.peek_error(ErrorCode::EofWhileParsingList)),
19571951
}
19581952
}
19591953

@@ -1984,32 +1978,30 @@ impl<'de, 'a, R: Read<'de> + 'a> de::MapAccess<'de> for MapAccess<'a, R> {
19841978
K: de::DeserializeSeed<'de>,
19851979
{
19861980
fn has_next_key<'de, 'a, R: Read<'de> + 'a>(map: &mut MapAccess<'a, R>) -> Result<bool> {
1987-
let peek = match tri!(map.de.parse_whitespace()) {
1988-
Some(b'}') => {
1989-
return Ok(false);
1990-
}
1981+
match tri!(map.de.parse_whitespace()) {
1982+
Some(b'}') => Ok(false),
19911983
Some(b',') if !map.first => {
19921984
map.de.eat_char();
1993-
tri!(map.de.parse_whitespace())
1985+
match tri!(map.de.parse_whitespace()) {
1986+
Some(b'"') => Ok(true),
1987+
Some(b'}') => Err(map.de.peek_error(ErrorCode::TrailingComma)),
1988+
Some(_) => Err(map.de.peek_error(ErrorCode::KeyMustBeAString)),
1989+
None => Err(map.de.peek_error(ErrorCode::EofWhileParsingValue)),
1990+
}
19941991
}
19951992
Some(b) => {
19961993
if map.first {
19971994
map.first = false;
1998-
Some(b)
1995+
if b == b'"' {
1996+
Ok(true)
1997+
} else {
1998+
Err(map.de.peek_error(ErrorCode::KeyMustBeAString))
1999+
}
19992000
} else {
2000-
return Err(map.de.peek_error(ErrorCode::ExpectedObjectCommaOrEnd));
2001+
Err(map.de.peek_error(ErrorCode::ExpectedObjectCommaOrEnd))
20012002
}
20022003
}
2003-
None => {
2004-
return Err(map.de.peek_error(ErrorCode::EofWhileParsingObject));
2005-
}
2006-
};
2007-
2008-
match peek {
2009-
Some(b'"') => Ok(true),
2010-
Some(b'}') => Err(map.de.peek_error(ErrorCode::TrailingComma)),
2011-
Some(_) => Err(map.de.peek_error(ErrorCode::KeyMustBeAString)),
2012-
None => Err(map.de.peek_error(ErrorCode::EofWhileParsingValue)),
2004+
None => Err(map.de.peek_error(ErrorCode::EofWhileParsingObject)),
20132005
}
20142006
}
20152007

0 commit comments

Comments
 (0)