pub struct JsonTreeBudgetTracker<R = JsonResource, Q = usize>where
Q: ResourceQuantity,{ /* 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,
impl<R, Q> JsonTreeBudgetTracker<R, Q>where
R: Clone,
Q: ResourceQuantity,
Sourcepub fn new(limits: JsonValueLimits<R, Q>) -> Self
pub fn new(limits: JsonValueLimits<R, Q>) -> Self
Sourcepub fn account(
&mut self,
value: &Value,
) -> Result<(), MeasuredBudgetError<R, Q>>
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.
Sourcepub fn reset(&mut self)
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.
Sourcepub const fn budget(&self) -> &JsonValueBudget<R, Q>
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.
Sourcepub fn budget_mut(&mut self) -> &mut JsonValueBudget<R, Q>
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.
Sourcepub fn into_budget(self) -> JsonValueBudget<R, Q>
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.