Skip to main content

JsonTreeReader

Struct JsonTreeReader 

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

Source

pub fn new( transaction: &'transaction mut JsonValueTransaction<'budget, R, Q>, ) -> Self

Creates a reader borrowing the supplied JSON value transaction.

§Parameters
  • transaction - Transaction receiving node and payload charges.
§Returns

A reader borrowing transaction for its lifetime.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'transaction, 'budget, R, Q> !UnwindSafe for JsonTreeReader<'transaction, 'budget, R, Q>

§

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

§

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

§

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

§

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

§

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

§

impl<'transaction, 'budget, R, Q> UnsafeUnpin for JsonTreeReader<'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.