pub struct JsonTreeReader<'transaction, 'budget, R, Q>where
Q: ResourceQuantity,{ /* private fields */ }Expand description
Processes JSON values while borrowing one staged JSON value transaction.
§Type Parameters
R- Resource identity tracked by the borrowed transaction.Q- Quantity representation used for resource accounting.
§Examples
use qubit_budget::json::{JsonResource, JsonValueBudget, JsonValueLimits};
use qubit_json::value::traverse::{
JsonTreeContext, JsonTreeReader, JsonTreeVisitor,
};
use serde_json::Value;
struct Visitor;
impl JsonTreeVisitor for Visitor {
type Error = std::convert::Infallible;
fn enter(
&mut self,
_: &Value,
_: JsonTreeContext<'_>,
) -> Result<(), Self::Error> {
Ok(())
}
}
let mut budget = JsonValueBudget::new(
JsonValueLimits::<JsonResource, usize>::default(),
);
let mut transaction = budget.transaction();
let mut reader = JsonTreeReader::new(&mut transaction);
assert!(reader.process(&Value::Null, &mut Visitor).is_ok());Implementations§
Source§impl<'transaction, 'budget, R, Q> JsonTreeReader<'transaction, 'budget, R, Q>where
R: Clone,
Q: ResourceQuantity,
impl<'transaction, 'budget, R, Q> JsonTreeReader<'transaction, 'budget, R, Q>where
R: Clone,
Q: ResourceQuantity,
Sourcepub fn new(
transaction: &'transaction mut JsonValueTransaction<'budget, R, Q>,
) -> Self
pub fn new( transaction: &'transaction mut JsonValueTransaction<'budget, R, Q>, ) -> Self
Sourcepub fn process<V>(
&mut self,
value: &Value,
visitor: &mut V,
) -> Result<(), JsonTreeProcessError<R, Q, V::Error>>where
V: JsonTreeVisitor,
pub fn process<V>(
&mut self,
value: &Value,
visitor: &mut V,
) -> Result<(), JsonTreeProcessError<R, Q, V::Error>>where
V: JsonTreeVisitor,
Processes every node in depth-first order without Rust recursion.
§Type Parameters
V- Visitor receiving admitted-node callbacks.
§Parameters
value- Root JSON value to process.visitor- Visitor invoked around each admitted node.
§Returns
Ok(()) after the complete tree is processed.
§Errors
Returns JsonTreeProcessError::Budget when resource admission fails,
or JsonTreeProcessError::Visitor when the visitor rejects a node.
Either error stops traversal immediately: remaining callbacks are not
invoked, and a node may not receive a matching leave callback. Any
visitor state or external side effects are the caller’s responsibility
and are not undone. This method neither commits nor rolls back the
borrowed transaction. A visitor error leaves prior charges staged in
that transaction; a budget error rejects the transaction so it cannot
be committed. Drop the transaction after an error and rebuild visitors
that require balanced callbacks or clean state.
Sourcepub fn account(
&mut self,
value: &Value,
) -> Result<(), MeasuredBudgetError<R, Q>>
pub fn account( &mut self, value: &Value, ) -> Result<(), MeasuredBudgetError<R, Q>>
Accounts every node and payload without invoking a domain visitor.
The charges remain staged in the borrowed transaction. The caller decides whether to commit it after any surrounding work succeeds.
§Parameters
value- Root JSON value whose complete tree is admitted.
§Returns
Ok(()) after every node and payload has been staged in the borrowed
transaction.
§Errors
Returns the first measured budget rejection encountered during the traversal.