#[non_exhaustive]pub enum JsonValueEncodeError<R, Q>where
Q: ResourceQuantity,{
Budget(MeasuredBudgetError<R, Q>),
Serialization(JsonSerializationError),
PrivateTextLimitExceeded {
maximum: usize,
},
}Expand description
Failure while projecting a Serde value into a budgeted JSON tree.
The error distinguishes resource budget rejection, strict JSON serialization failure, and private text payloads that exceed their configured limit. Because this type is non-exhaustive, matches outside this crate must include a fallback arm. After any failure, discard the entire caller-owned resource transaction; do not treat its partial measurements as a successful projection.
None from a serialization query does not indicate success. It means that
the error is not a serialization failure.
§Type Parameters
Ris the resource identifier type used by the budget.Qis the resource quantity type and must implementResourceQuantity.
§Examples
use qubit_budget::json::JsonResource;
use qubit_budget::json::JsonValueBudget;
use qubit_budget::json::JsonValueLimits;
use qubit_json::value::JsonValueEncodeError;
use qubit_json::value::JsonValueEncoder;
use serde_json::value::RawValue;
let limits = JsonValueLimits::<JsonResource, usize>::new();
let mut budget = JsonValueBudget::new(limits);
let mut transaction = budget.transaction();
let raw = RawValue::from_string("null".to_owned()).unwrap();
let error = JsonValueEncoder::new()
.encode_in_transaction_with_private_text_limit(&raw, &mut transaction, 0)
.unwrap_err();
let classification = match &error {
JsonValueEncodeError::Budget(_) => "budget",
JsonValueEncodeError::Serialization(_) => "serialization",
JsonValueEncodeError::PrivateTextLimitExceeded { maximum } => {
assert_eq!(*maximum, 0);
"private text limit"
}
_ => "other",
};
assert_eq!(classification, "private text limit");
assert!(error.serialization_error().is_none());
assert!(error.kind().is_none());
assert!(error.category().is_none());
drop(transaction);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Budget(MeasuredBudgetError<R, Q>)
The caller’s resource transaction rejected a value.
Tuple Fields
0: MeasuredBudgetError<R, Q>The measured resource or quantity that caused admission to fail.
Serialization(JsonSerializationError)
The Serde value could not be represented as strict JSON.
Tuple Fields
0: JsonSerializationErrorThe privacy-safe strict JSON serialization failure.
PrivateTextLimitExceeded
A private RawValue or Number payload exceeded its configured UTF-8 text limit.
Implementations§
Source§impl<R, Q> JsonValueEncodeError<R, Q>where
Q: ResourceQuantity,
impl<R, Q> JsonValueEncodeError<R, Q>where
Q: ResourceQuantity,
Sourcepub const fn serialization_error(&self) -> Option<&JsonSerializationError>
pub const fn serialization_error(&self) -> Option<&JsonSerializationError>
Returns the underlying serialization error when Serde projection failed.
§Returns
Returns Some for Self::Serialization. Returns None for
Self::Budget and Self::PrivateTextLimitExceeded; None means
the failure is not a serialization error, not that projection
succeeded.
Sourcepub const fn kind(&self) -> Option<JsonSerializationErrorKind>
pub const fn kind(&self) -> Option<JsonSerializationErrorKind>
Returns the stable serialization failure kind, if applicable.
§Returns
Returns Some for Self::Serialization. Returns None for
Self::Budget and Self::PrivateTextLimitExceeded; None means
the failure has no serialization kind, not that projection succeeded.
Sourcepub const fn category(&self) -> Option<JsonSerializationErrorCategory>
pub const fn category(&self) -> Option<JsonSerializationErrorCategory>
Returns the broad serialization category, if applicable.
§Returns
Returns Some for Self::Serialization. Returns None for
Self::Budget and Self::PrivateTextLimitExceeded; None means
the failure has no serialization category, not that projection
succeeded.
Sourcepub const fn is_number_error(&self) -> bool
pub const fn is_number_error(&self) -> bool
Reports whether the serialization failure concerns a JSON number.
Sourcepub const fn is_map_key_error(&self) -> bool
pub const fn is_map_key_error(&self) -> bool
Reports whether the serialization failure concerns an object key.
Sourcepub const fn is_raw_value_error(&self) -> bool
pub const fn is_raw_value_error(&self) -> bool
Reports whether the serialization failure concerns a raw JSON value.
Sourcepub const fn is_serializer_contract_error(&self) -> bool
pub const fn is_serializer_contract_error(&self) -> bool
Reports whether Serde violated a serializer protocol contract.
Sourcepub const fn integer_signedness(&self) -> Option<JsonIntegerSignedness>
pub const fn integer_signedness(&self) -> Option<JsonIntegerSignedness>
Returns the rejected integer signedness, if applicable.
Sourcepub const fn map_key_kind(&self) -> Option<JsonMapKeyKind>
pub const fn map_key_kind(&self) -> Option<JsonMapKeyKind>
Returns the unsupported map-key category, if applicable.
Sourcepub const fn collection_kind(&self) -> Option<JsonCollectionKind>
pub const fn collection_kind(&self) -> Option<JsonCollectionKind>
Returns the collection whose length overflowed, if applicable.
Sourcepub const fn serializer_state_error(&self) -> Option<JsonSerializerStateError>
pub const fn serializer_state_error(&self) -> Option<JsonSerializerStateError>
Returns the serializer protocol state failure, if applicable.
Trait Implementations§
Source§impl<R: Debug, Q> Debug for JsonValueEncodeError<R, Q>where
Q: ResourceQuantity + Debug,
impl<R: Debug, Q> Debug for JsonValueEncodeError<R, Q>where
Q: ResourceQuantity + Debug,
Source§impl<R, Q> Display for JsonValueEncodeError<R, Q>where
Q: ResourceQuantity,
impl<R, Q> Display for JsonValueEncodeError<R, Q>where
Q: ResourceQuantity,
Source§impl<R, Q> Error for JsonValueEncodeError<R, Q>where
R: Debug + 'static,
Q: ResourceQuantity + 'static,
impl<R, Q> Error for JsonValueEncodeError<R, Q>where
R: Debug + 'static,
Q: ResourceQuantity + 'static,
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the underlying budget or serialization cause, when present.
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()