pub struct AccountingJsonValueSeed<'transaction, 'budget, R, Q = usize>where
Q: ResourceQuantity,{ /* private fields */ }Expand description
Serde seed that constructs a Value while accounting decoded resources.
Unlike lexical JSON admission, this seed observes values after a Serde
deserializer has decoded them. It cannot inspect original number lexemes or
enforce text-level integer and floating-point range rules. Use
JsonDecoder when decoding JSON text requires those guarantees. This seed
remains suitable for decoded-value budget enforcement inside a type’s
ordinary serde::Deserialize implementation, where the original input
bytes are unavailable.
Do not pass this seed to crate::decode::JsonDecoder::decode_seed_str or
crate::decode::JsonDecoder::decode_seed_utf8 when its transaction and
the decoder represent the same logical decoded-value budget. JsonDecoder
already accounts the complete value during lexical admission, so the seed
would charge that value a second time. In that pipeline, use a seed that
performs only domain deserialization and domain-specific checks.
§Type Parameters
R- Resource identity tracked by the value transaction.Q- Quantity representation used for resource accounting.
§Examples
use qubit_budget::json::{JsonResource, JsonValueBudget, JsonValueLimits};
use qubit_json::value::AccountingJsonValueSeed;
use serde::de::DeserializeSeed;
let mut budget = JsonValueBudget::new(JsonValueLimits::<JsonResource, usize>::default());
let mut transaction = budget.transaction();
let mut deserializer = serde_json::Deserializer::from_str(r#"{"ok":true}"#);
let value = AccountingJsonValueSeed::new(&mut transaction).deserialize(&mut deserializer)?;
assert_eq!(value["ok"], true);
transaction.commit()?;Implementations§
Source§impl<'transaction, 'budget, R, Q> AccountingJsonValueSeed<'transaction, 'budget, R, Q>where
Q: ResourceQuantity,
impl<'transaction, 'budget, R, Q> AccountingJsonValueSeed<'transaction, 'budget, R, Q>where
Q: ResourceQuantity,
Sourcepub fn new(
transaction: &'transaction mut JsonValueTransaction<'budget, R, Q>,
) -> Self
pub fn new( transaction: &'transaction mut JsonValueTransaction<'budget, R, Q>, ) -> Self
Creates a root seed using the supplied decoded-value transaction.
§Parameters
transaction- Transaction receiving decoded JSON resource charges. It must not duplicate decoded-value accounting already performed by an outercrate::decode::JsonDecoder.
§Returns
A seed that constructs one accounted Value tree.