Skip to main content

JsonDecodeError

Struct JsonDecodeError 

Source
pub struct JsonDecodeError<R = JsonResource, Q = usize>
where Q: Copy + Debug,
{ /* private fields */ }
Expand description

Failure produced by either strict or normalizing JSON decoding.

Internal variants are private so callers branch through stable semantic accessors rather than depending on scanner, normalizer, or Serde details.

§Type Parameters

  • R - Resource identity attached to budget failures.
  • Q - Quantity representation attached to budget failures.

§Examples

use qubit_json::decode::{JsonDecodeError, JsonDecodeErrorKind, JsonDecoder};
use serde_json::Value;

let mut decoder = JsonDecoder::unlimited();
let error: JsonDecodeError = decoder
    .decode_str::<Value>("")
    .expect_err("empty input must be rejected");
assert_eq!(error.kind(), JsonDecodeErrorKind::InvalidJson);

Implementations§

Source§

impl<R, Q> JsonDecodeError<R, Q>
where Q: Copy + Debug,

Source

pub const fn kind(&self) -> JsonDecodeErrorKind

Returns the stable failure category.

§Returns

The category describing which kind of decode operation failed.

Source

pub const fn stage(&self) -> JsonDecodeStage

Returns the semantic stage that produced the failure.

§Returns

The pipeline stage at which the failure was recorded.

Source

pub const fn diagnostic_policy(&self) -> DiagnosticPolicy

Returns the diagnostic policy applied while constructing this error.

§Returns

The policy that determines whether input-derived details are retained.

Source

pub const fn raw_input_bytes(&self) -> usize

Returns the original input length in bytes.

§Returns

The number of bytes charged for the input that caused this error.

Source

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

Returns the normalized text length when normalization completed.

§Returns

Some(length) when normalization produced text, or None when the failure occurred before a normalized document existed.

Source

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

Returns the one-based error line when available.

§Returns

Some(line) for failures with source coordinates, otherwise None.

Source

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

Returns the one-based error column when available.

§Returns

Some(column) for failures with source coordinates, otherwise None.

Source

pub const fn syntax_error(&self) -> Option<&JsonSyntaxError>

Returns the structured syntax failure for invalid JSON.

§Returns

A borrowed syntax error when parsing failed, otherwise None.

Source

pub const fn budget_error(&self) -> Option<&MeasuredBudgetError<R, Q>>

Returns the complete measured-budget failure when present.

§Returns

A borrowed budget error when resource accounting rejected the input, otherwise None.

Source

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

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

§Returns

Some(bytes) for an invalid UTF-8 failure, or None for other failure kinds.

Source

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

Returns the invalid UTF-8 sequence length when known.

§Returns

The length of the invalid sequence when the decoder can determine it, otherwise None.

Source

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

Returns the expected top-level kind for a constrained decode failure.

§Returns

The required root kind when a constrained operation failed, otherwise None.

Source

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

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

§Returns

The root kind observed in the valid document, otherwise None.

Source

pub fn into_source(self) -> JsonDecodeErrorSource<R, Q>

Consumes this error and returns its owned semantic source.

Unlike the kind-specific accessors, this operation preserves the complete mutually exclusive failure state. Input-derived third-party sources remain present only when the decoder used DiagnosticPolicy::Detailed.

§Returns

The structured budget, input, syntax, top-level, or deserialization source retained by this error.

Trait Implementations§

Source§

impl<R: Clone, Q> Clone for JsonDecodeError<R, Q>
where Q: Copy + Debug + Clone,

Source§

fn clone(&self) -> JsonDecodeError<R, Q>

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<R, Q> Debug for JsonDecodeError<R, Q>
where R: Debug, Q: Copy + Debug,

Source§

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

Formats structured diagnostics retained under the active policy.

Source§

impl<R, Q> Display for JsonDecodeError<R, Q>
where R: Debug, Q: ResourceQuantity,

Source§

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

Formats a privacy-safe or detailed message according to the policy.

Source§

impl<R, Q> Error for JsonDecodeError<R, Q>
where R: Debug + 'static, Q: ResourceQuantity + 'static,

Source§

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

Returns budget sources unconditionally and input-derived sources only when detailed diagnostics retained them.

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

Auto Trait Implementations§

§

impl<R = JsonResource, Q = usize> !RefUnwindSafe for JsonDecodeError<R, Q>

§

impl<R = JsonResource, Q = usize> !UnwindSafe for JsonDecodeError<R, Q>

§

impl<R, Q> Freeze for JsonDecodeError<R, Q>

§

impl<R, Q> Send for JsonDecodeError<R, Q>

§

impl<R, Q> Sync for JsonDecodeError<R, Q>

§

impl<R, Q> Unpin for JsonDecodeError<R, Q>

§

impl<R, Q> UnsafeUnpin for JsonDecodeError<R, Q>

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.