pub struct JsonEncodeError<R, Q = usize>{ /* 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>
impl<R, Q> JsonEncodeError<R, Q>
Sourcepub const fn kind(&self) -> JsonEncodeErrorKind
pub const fn kind(&self) -> JsonEncodeErrorKind
Returns the stable failure category.
§Returns
The category describing which encoding operation failed.
Sourcepub const fn budget_error(&self) -> Option<&MeasuredBudgetError<R, Q>>
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.
Sourcepub const fn syntax_error(&self) -> Option<&JsonSyntaxError>
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.
Sourcepub const fn serialization_error(&self) -> Option<&JsonSerializationError>
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.
Sourcepub const fn write_error(&self) -> Option<&IoError>
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.
Sourcepub fn into_budget_error(self) -> Option<MeasuredBudgetError<R, Q>>
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.
Sourcepub fn into_syntax_error(self) -> Option<JsonSyntaxError>
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.
Sourcepub fn into_serialization_error(self) -> Option<JsonSerializationError>
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.
Sourcepub fn into_write_error(self) -> Option<IoError>
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.
Sourcepub fn into_source(self) -> JsonEncodeErrorSource<R, Q>
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>
impl<R: Debug, Q> Debug for JsonEncodeError<R, Q>
Source§impl<R, Q> Display for JsonEncodeError<R, Q>
impl<R, Q> Display for JsonEncodeError<R, Q>
Source§impl<R, Q> Error for JsonEncodeError<R, Q>
impl<R, Q> Error for JsonEncodeError<R, Q>
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
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
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl<R, Q> From<MeasuredBudgetError<R, Q>> for JsonEncodeError<R, Q>
impl<R, Q> From<MeasuredBudgetError<R, Q>> for JsonEncodeError<R, Q>
Source§fn from(source: MeasuredBudgetError<R, Q>) -> Self
fn from(source: MeasuredBudgetError<R, Q>) -> Self
Converts a measured-budget failure into an encoding failure.