Skip to main content

ErrorKind

Enum ErrorKind 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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.

Implementations§

Source§

impl ErrorKind

Source

pub const fn is_budget(self) -> bool

Whether this error comes from a budget in Limits rather than from the input being invalid JSON. The same input may parse with larger limits.

§Examples
use jsonx_lib::ErrorKind;

assert!(ErrorKind::DepthLimitExceeded.is_budget());
assert!(!ErrorKind::TrailingComma.is_budget());

Trait Implementations§

Source§

impl Clone for ErrorKind

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ErrorKind

Source§

impl Debug for ErrorKind

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ErrorKind

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for ErrorKind

Source§

impl Hash for ErrorKind

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ErrorKind

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ErrorKind

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.