Skip to main content

JsonTreeBudgetTracker

Struct JsonTreeBudgetTracker 

Source
pub struct JsonTreeBudgetTracker<R = JsonResource, Q = usize>{ /* private fields */ }
Expand description

Fully accounts materialized JSON trees using an internally owned budget.

§Type Parameters

  • R - Resource identity tracked by the owned value budget.
  • Q - Quantity representation used for resource accounting.

§Examples

use qubit_budget::json::{JsonResource, JsonValueLimits};
use qubit_json::value::traverse::JsonTreeBudgetTracker;
use serde_json::json;

let mut tracker = JsonTreeBudgetTracker::<JsonResource, usize>::new(
    JsonValueLimits::default(),
);
assert!(tracker.account(&json!({"ok": true})).is_ok());

Implementations§

Source§

impl<R, Q> JsonTreeBudgetTracker<R, Q>
where R: Clone, Q: ResourceQuantity,

Source

pub fn new(limits: JsonValueLimits<R, Q>) -> Self

Creates a full-tree tracker with fresh budget state.

§Parameters
  • limits - Resource limits used by the owned budget.
§Returns

A tracker initialized with the supplied limits.

Source

pub fn account( &mut self, value: &Value, ) -> Result<(), MeasuredBudgetError<R, Q>>

Charges every node and payload represented by value.

§Parameters
  • value - JSON tree whose resources are charged.
§Returns

Ok(()) when the complete tree is admitted.

§Errors

Returns the first measured budget rejection encountered while walking the tree. Charges are committed only when the complete walk succeeds.

Source

pub fn reset(&mut self)

Restores the owned budget to its original configured state.

This clears accumulated charges and makes the tracker ready for a new independent accounting run.

Resetting does not change the configured limits or resource identities; it only discards usage accumulated since construction or the previous reset.

Source

pub const fn budget(&self) -> &JsonValueBudget<R, Q>

Returns the owned budget for read-only inspection.

§Returns

A shared reference to the accumulated budget state.

Source

pub fn budget_mut(&mut self) -> &mut JsonValueBudget<R, Q>

Returns the owned budget for caller-managed accounting.

§Returns

A mutable reference to the accumulated budget state.

Source

pub fn into_budget(self) -> JsonValueBudget<R, Q>

Consumes this tracker and returns its accumulated budget state.

§Returns

The owned budget, including all charges accumulated by this tracker.

Auto Trait Implementations§

§

impl<R, Q> Freeze for JsonTreeBudgetTracker<R, Q>
where JsonValueBudget<R, Q>: Freeze,

§

impl<R, Q> RefUnwindSafe for JsonTreeBudgetTracker<R, Q>

§

impl<R, Q> Send for JsonTreeBudgetTracker<R, Q>
where JsonValueBudget<R, Q>: Send,

§

impl<R, Q> Sync for JsonTreeBudgetTracker<R, Q>
where JsonValueBudget<R, Q>: Sync,

§

impl<R, Q> Unpin for JsonTreeBudgetTracker<R, Q>
where JsonValueBudget<R, Q>: Unpin,

§

impl<R, Q> UnsafeUnpin for JsonTreeBudgetTracker<R, Q>

§

impl<R, Q> UnwindSafe for JsonTreeBudgetTracker<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.