#[non_exhaustive]pub enum ErrorKind {
Show 23 variants
UnexpectedEnd,
ExpectedValue,
ExpectedColon,
ExpectedCommaOrBracket,
ExpectedCommaOrBrace,
ExpectedKey,
TrailingComma,
TrailingCharacters,
InvalidLiteral,
InvalidNumber,
InvalidEscape,
InvalidUnicodeEscape,
LoneSurrogate,
ControlCharacter,
InvalidUtf8,
DuplicateKey,
DepthLimitExceeded,
InputTooLarge,
StringTooLong,
NumberTooLong,
TooManyElements,
MemoryLimitExceeded,
InputAfterEnd,
}Expand description
The kinds of Error.
The enum is #[non_exhaustive]: later versions may report a case more
precisely with a new variant, so a match needs a wildcard arm.
§Examples
use jsonx_lib::{parse, ErrorKind};
match parse("[1, 2").unwrap_err().kind() {
ErrorKind::UnexpectedEnd => { /* the input was cut short: wait for more */ }
_ => { /* the input is malformed */ }
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
UnexpectedEnd
The input ended inside a value, or held no value at all. The input is a truncated document; with a stream, wait for more bytes.
ExpectedValue
A value was expected and this byte cannot start one (values start with
{, [, ", -, a digit, t, f, or n).
ExpectedColon
An object key must be followed by :.
ExpectedCommaOrBracket
Inside an array, a value must be followed by , or ].
ExpectedCommaOrBrace
Inside an object, a member must be followed by , or }.
ExpectedKey
An object key was expected: a member must start with a string.
TrailingComma
A , came directly before the ] or } closing its array or
object. JSON does not allow trailing commas.
TrailingCharacters
The document’s value ended, but non-whitespace input followed it.
InvalidLiteral
The input started true, false, or null but did not finish it.
InvalidNumber
A number broke the RFC 8259 number grammar: a leading zero, a missing
digit after -, ., or the exponent marker, and so on.
InvalidEscape
A backslash in a string was followed by a character that is not one of
" \ / b f n r t u.
InvalidUnicodeEscape
A \u escape was not followed by four hexadecimal digits.
LoneSurrogate
A \u escape named half of a UTF-16 surrogate pair without the other
half. Such a string has no Unicode text to decode to; the offset is the
backslash of the unpaired escape.
ControlCharacter
A string contained an unescaped control character (U+0000 to U+001F). Control characters must be written as escapes.
InvalidUtf8
The input was not valid UTF-8 (parse_bytes
only). The offset is the first byte of the invalid sequence.
DuplicateKey
An object repeated a key, under DuplicateKeys::Error
(the default). The offset is the second occurrence’s opening quote.
Duplicates are found when the object closes, so a syntax error later in
the same object is reported first.
DepthLimitExceeded
Containers nested deeper than Limits::max_depth.
The offset is the [ or { that went one level too deep.
InputTooLarge
The input is longer than Limits::max_input_bytes.
The offset is the limit: the first byte past the budget.
StringTooLong
A string (or key) is longer than Limits::max_string_bytes,
counted in source bytes between the quotes. The offset is its opening quote.
NumberTooLong
A number’s text is longer than Limits::max_number_bytes.
The offset is the number’s first byte.
TooManyElements
The document holds more values than Limits::max_elements.
The offset is the first byte of the value that went over.
MemoryLimitExceeded
Building the document’s tree would hold more memory than
Limits::max_memory. The offset is the
first byte of the value whose storage went over.
InputAfterEnd
Bytes were fed to a StreamReader after
end_input said the input had
ended. A mistake in the calling code, not in the document; the
offset is the number of bytes accepted before the end.