Skip to main content

JsonEncodeError

Struct JsonEncodeError 

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

Failure produced while encoding one JSON document.

Internal failure variants remain private. Callers branch through JsonEncodeErrorKind and inspect sources through stable accessors rather than depending on the encoder’s representation.

§Type Parameters

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

§Examples

use qubit_json::encode::JsonEncodeErrorKind;
use qubit_json::encode::JsonEncoder;

let mut encoder = JsonEncoder::unlimited();
let error = encoder
    .to_vec(&u128::MAX)
    .expect_err("wide integer must not serialize as JSON");
assert_eq!(error.kind(), JsonEncodeErrorKind::Serialize);
assert!(error.serialization_error().is_some());

Implementations§

Source§

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

Source

pub const fn kind(&self) -> JsonEncodeErrorKind

Returns the stable failure category.

§Returns

The category describing which encoding operation failed.

Source

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

Returns the measured budget failure when accounting rejected work.

§Returns

Some with the borrowed budget error for JsonEncodeErrorKind::Budget, or None for every other failure kind.

Source

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

Returns the syntax error retained for invalid raw JSON.

§Returns

Some with the borrowed syntax error for JsonEncodeErrorKind::InvalidRawJson, or None otherwise.

Source

pub const fn serialization_error(&self) -> Option<&JsonSerializationError>

Returns the privacy-safe Serde serialization error when present.

§Returns

Some with the borrowed serialization error for JsonEncodeErrorKind::Serialize, or None otherwise.

Source

pub const fn write_error(&self) -> Option<&IoError>

Returns the destination-writer error when present.

§Returns

Some with the borrowed I/O error for JsonEncodeErrorKind::Write, or None otherwise.

Source

pub fn into_budget_error(self) -> Option<MeasuredBudgetError<R, Q>>

Consumes this error and returns its measured budget source when present.

§Returns

Some with the owned budget error for JsonEncodeErrorKind::Budget, or None otherwise.

Source

pub fn into_syntax_error(self) -> Option<JsonSyntaxError>

Consumes this error and returns its syntax source when present.

§Returns

Some with the owned syntax error for JsonEncodeErrorKind::InvalidRawJson, or None otherwise.

Source

pub fn into_serialization_error(self) -> Option<JsonSerializationError>

Consumes this error and returns its serialization source when present.

§Returns

Some with the owned serialization error for JsonEncodeErrorKind::Serialize, or None otherwise.

Source

pub fn into_write_error(self) -> Option<IoError>

Consumes this error and returns its destination-writer source when present.

§Returns

Some with the owned I/O error for JsonEncodeErrorKind::Write, or None otherwise.

Source

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

Consumes this error and returns its owned underlying source.

Unlike the kind-specific into_* methods, this operation never drops a non-matching error. Callers can exhaustively map every source with one match expression.

§Returns

The budget, raw-JSON syntax, serialization, or destination-writer source retained by this error.

Trait Implementations§

Source§

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

Source§

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

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

impl<R, Q> Display for JsonEncodeError<R, Q>
where R: Debug, Q: Copy + Debug + Display,

Source§

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

Formats the retained source without exposing encoder internals.

Source§

impl<R, Q> Error for JsonEncodeError<R, Q>
where R: Debug + 'static, Q: Copy + Debug + Display + 'static,

Source§

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

Returns the structured budget, syntax, serialization, or I/O source.

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

Source§

fn from(source: MeasuredBudgetError<R, Q>) -> Self

Converts a measured-budget failure into an encoding failure.

Auto Trait Implementations§

§

impl<R, Q = usize> !RefUnwindSafe for JsonEncodeError<R, Q>

§

impl<R, Q = usize> !UnwindSafe for JsonEncodeError<R, Q>

§

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

§

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

§

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

§

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

§

impl<R, Q> UnsafeUnpin for JsonEncodeError<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> 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> 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.