Skip to main content

JsonDecodeError

Struct JsonDecodeError 

Source
#[non_exhaustive]
pub struct JsonDecodeError { /* private fields */ }
Expand description

Error returned when lenient JSON decoding fails.

This type exposes immutable diagnostics so its error category, stage, and associated input metadata always remain consistent with one another.

Implementations§

Source§

impl JsonDecodeError

Source

pub const fn kind(&self) -> JsonDecodeErrorKind

Returns the stable category of this decoding failure.

§Returns

The stable error category.

Source

pub const fn stage(&self) -> JsonDecodeStage

Returns the decoding stage that produced this error.

§Returns

The decoder stage where the failure occurred.

Source

pub const fn privacy_policy(&self) -> ErrorPrivacyPolicy

Returns the privacy policy applied when this error was constructed.

§Returns

The effective error privacy policy.

Source

pub fn message(&self) -> &str

Returns the human-readable diagnostic message.

§Returns

The stable redacted message or explicitly requested detailed message.

Source

pub const fn expected_top_level(&self) -> Option<JsonTopLevelKind>

Returns the required top-level JSON kind for a constrained decode.

§Returns

Some(kind) when constrained decoding rejected a valid top-level value; otherwise, None.

Source

pub const fn actual_top_level(&self) -> Option<JsonTopLevelKind>

Returns the observed top-level JSON kind for a constrained decode.

§Returns

Some(kind) when constrained decoding rejected a valid top-level value; otherwise, None.

Source

pub const fn raw_input_bytes(&self) -> usize

Returns the byte length of the input before normalization.

§Returns

The raw input length in bytes.

Source

pub fn utf8_valid_up_to(&self) -> Option<usize>

Returns the valid UTF-8 prefix length for invalid byte input.

§Returns

Some(length) for JsonDecodeErrorKind::InvalidUtf8, including zero when the first byte is invalid; otherwise, None.

Source

pub fn utf8_error_len(&self) -> Option<usize>

Returns the known length of the invalid UTF-8 sequence.

§Returns

Some(length) when the invalid sequence length is known, or None for an incomplete trailing sequence and for non-UTF-8 errors.

Source

pub const fn normalized_input_bytes(&self) -> Option<usize>

Returns the byte length of normalized JSON text.

§Returns

Some(length) when normalization completed before the failure, or None when the input was rejected before a normalized length existed.

Source

pub const fn max_input_bytes(&self) -> Option<usize>

Returns the configured raw-input limit for a size failure.

§Returns

Some(limit) when raw input exceeded its configured limit, or None for normalized-size and non-size failures.

Source

pub const fn max_normalized_bytes(&self) -> Option<usize>

Returns the configured normalized-input limit for a size failure.

§Returns

Some(limit) when normalized JSON exceeded its configured limit, or None for raw-size and non-size failures.

Source

pub const fn normalized_line(&self) -> Option<usize>

Returns the parser line in normalized JSON text.

§Returns

Some(line) with a one-based line number when serde reported one, or None when no parser location is available.

Source

pub const fn normalized_column(&self) -> Option<usize>

Returns the parser column in normalized JSON text.

§Returns

Some(column) with a one-based column number when serde reported one, or None when no parser location is available.

Trait Implementations§

Source§

impl Clone for JsonDecodeError

Source§

fn clone(&self) -> JsonDecodeError

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 Debug for JsonDecodeError

Source§

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

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

impl Display for JsonDecodeError

Source§

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

Writes the configured human-readable diagnostic message.

§Parameters
  • f - Destination formatter.
§Returns

Ok(()) when the message is written successfully.

§Errors

Returns a formatting error when the destination formatter rejects the write.

Source§

impl Eq for JsonDecodeError

Source§

impl Error for JsonDecodeError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the decoder source under detailed privacy mode.

§Returns

Some(source) when detailed diagnostics expose a UTF-8 or serde error, or None for redacted and source-free failures.

1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl PartialEq for JsonDecodeError

Source§

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

Compares all stable error fields while ignoring the retained source.

§Parameters
  • other - Error to compare with this error.
§Returns

true when every stable diagnostic field is equal; otherwise, false.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.