Skip to main content

AccountingJsonValueSeed

Struct AccountingJsonValueSeed 

Source
pub struct AccountingJsonValueSeed<'transaction, 'budget, R, Q = usize>{ /* 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>

Source

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 outer crate::decode::JsonDecoder.
§Returns

A seed that constructs one accounted Value tree.

Trait Implementations§

Source§

impl<'de, R, Q> DeserializeSeed<'de> for AccountingJsonValueSeed<'_, '_, R, Q>
where R: Clone + Debug, Q: ResourceQuantity,

Source§

fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where D: Deserializer<'de>,

Builds one value through the accounting visitor.

Source§

type Value = Value

The type produced by using this seed.

Auto Trait Implementations§

§

impl<'transaction, 'budget, R, Q = usize> !UnwindSafe for AccountingJsonValueSeed<'transaction, 'budget, R, Q>

§

impl<'transaction, 'budget, R, Q> Freeze for AccountingJsonValueSeed<'transaction, 'budget, R, Q>
where &'transaction mut JsonValueTransaction<'budget, R, Q>: Freeze,

§

impl<'transaction, 'budget, R, Q> RefUnwindSafe for AccountingJsonValueSeed<'transaction, 'budget, R, Q>
where &'transaction mut JsonValueTransaction<'budget, R, Q>: RefUnwindSafe,

§

impl<'transaction, 'budget, R, Q> Send for AccountingJsonValueSeed<'transaction, 'budget, R, Q>
where &'transaction mut JsonValueTransaction<'budget, R, Q>: Send,

§

impl<'transaction, 'budget, R, Q> Sync for AccountingJsonValueSeed<'transaction, 'budget, R, Q>
where &'transaction mut JsonValueTransaction<'budget, R, Q>: Sync,

§

impl<'transaction, 'budget, R, Q> Unpin for AccountingJsonValueSeed<'transaction, 'budget, R, Q>
where &'transaction mut JsonValueTransaction<'budget, R, Q>: Unpin,

§

impl<'transaction, 'budget, R, Q> UnsafeUnpin for AccountingJsonValueSeed<'transaction, 'budget, R, Q>
where &'transaction mut JsonValueTransaction<'budget, R, Q>: UnsafeUnpin,

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.