Skip to main content

JsonEncodeErrorSource

Enum JsonEncodeErrorSource 

Source
pub enum JsonEncodeErrorSource<R, Q = usize>
where Q: Copy + Debug,
{ Budget(MeasuredBudgetError<R, Q>), InvalidRawJson(JsonSyntaxError), Serialize(JsonSerializationError), Write(Error), }
Expand description

An owned source extracted from a strict JSON encoding failure.

This enum lets callers move an underlying failure into another error model with one exhaustive match. It avoids checking an error kind and then using a separate optional extractor whose success depends on that prior check.

§Type Parameters

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

§Examples

use qubit_budget::json::JsonResource;
use qubit_json::encode::JsonEncodeErrorSource;
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");
match error.into_source() {
    JsonEncodeErrorSource::Serialize(source) => {
        assert!(source.is_number_error());
    }
    source => panic!("unexpected encoding source: {source:?}"),
}

Variants§

§

Budget(MeasuredBudgetError<R, Q>)

Resource accounting rejected the encoded work or output.

§

InvalidRawJson(JsonSyntaxError)

A serde_json::value::RawValue payload was not strict JSON.

§

Serialize(JsonSerializationError)

Serde rejected the source value during strict serialization.

§

Write(Error)

The destination writer rejected an output operation.

Trait Implementations§

Source§

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

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

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