Skip to main content

JsonTreeMutator

Struct JsonTreeMutator 

Source
pub struct JsonTreeMutator<'input_transaction, 'input_budget, 'output_transaction, 'output_budget, R, Q>{ /* private fields */ }
Expand description

Mutates a JSON tree between independent input and output transactions.

The complete original tree is admitted before the first visitor callback. After all callbacks succeed, the complete mutated tree is admitted against the output transaction. Visitor failures and panics can retain partial mutations, while output accounting does not begin until visitor success.

§Type Parameters

  • R - Resource identity shared by the two transactions.
  • Q - Quantity representation shared by the two transactions.

§Examples

use qubit_budget::json::{JsonResource, JsonValueBudget, JsonValueLimits};
use qubit_json::value::traverse::{
    JsonTreeContext, JsonTreeControl, JsonTreeMutVisitor, JsonTreeMutator,
};
use serde_json::Value;

struct Visitor;
impl JsonTreeMutVisitor for Visitor {
    type Error = std::convert::Infallible;

    fn visit(
        &mut self,
        _: &mut Value,
        _: JsonTreeContext<'_>,
    ) -> Result<JsonTreeControl, Self::Error> {
        Ok(JsonTreeControl::SkipSubtree)
    }
}

let limits = JsonValueLimits::<JsonResource, usize>::default();
let mut input_budget = JsonValueBudget::new(limits);
let mut output_budget = JsonValueBudget::new(limits);
let mut input = input_budget.transaction();
let mut output = output_budget.transaction();
let mut mutator = JsonTreeMutator::new(&mut input, &mut output);
let mut value = Value::Null;
assert!(mutator.process(&mut value, &mut Visitor).is_ok());

Implementations§

Source§

impl<'input_transaction, 'input_budget, 'output_transaction, 'output_budget, R, Q> JsonTreeMutator<'input_transaction, 'input_budget, 'output_transaction, 'output_budget, R, Q>
where R: Clone, Q: ResourceQuantity,

Source

pub fn new( input: &'input_transaction mut JsonValueTransaction<'input_budget, R, Q>, output: &'output_transaction mut JsonValueTransaction<'output_budget, R, Q>, ) -> Self

Creates a mutator borrowing independent input and output transactions.

§Parameters
  • input - Transaction receiving charges for the complete original tree.
  • output - Transaction receiving charges for the complete mutated tree.
§Returns

A mutator borrowing both transactions for its lifetime.

Source

pub fn process<V>( &mut self, root: &mut Value, visitor: &mut V, ) -> Result<(), JsonTreeMutateError<R, Q, V::Error>>

Admits the original tree, mutates it, and admits the final tree.

Both admissions and all visitor callbacks use explicit stacks rather than Rust recursion. SkipSubtree affects callbacks only; final output admission always covers every resulting descendant.

§Type Parameters
  • V - Visitor controlling mutations and descendant callbacks.
§Parameters
  • root - Root JSON value to process and mutate.
  • visitor - Visitor applied after complete input admission.
§Returns

Ok(()) after both complete trees fit and every callback succeeds.

§Errors

Returns JsonTreeMutateError::InputBudget before mutation when the original tree is rejected, JsonTreeMutateError::Visitor after a callback failure, or JsonTreeMutateError::OutputBudget after a complete mutation whose result is rejected. Visitor and output failures retain mutations already made to root.

Auto Trait Implementations§

§

impl<'input_transaction, 'input_budget, 'output_transaction, 'output_budget, R, Q> !UnwindSafe for JsonTreeMutator<'input_transaction, 'input_budget, 'output_transaction, 'output_budget, R, Q>

§

impl<'input_transaction, 'input_budget, 'output_transaction, 'output_budget, R, Q> Freeze for JsonTreeMutator<'input_transaction, 'input_budget, 'output_transaction, 'output_budget, R, Q>
where &'input_transaction mut JsonValueTransaction<'input_budget, R, Q>: Freeze, &'output_transaction mut JsonValueTransaction<'output_budget, R, Q>: Freeze,

§

impl<'input_transaction, 'input_budget, 'output_transaction, 'output_budget, R, Q> RefUnwindSafe for JsonTreeMutator<'input_transaction, 'input_budget, 'output_transaction, 'output_budget, R, Q>
where &'input_transaction mut JsonValueTransaction<'input_budget, R, Q>: RefUnwindSafe, &'output_transaction mut JsonValueTransaction<'output_budget, R, Q>: RefUnwindSafe,

§

impl<'input_transaction, 'input_budget, 'output_transaction, 'output_budget, R, Q> Send for JsonTreeMutator<'input_transaction, 'input_budget, 'output_transaction, 'output_budget, R, Q>
where &'input_transaction mut JsonValueTransaction<'input_budget, R, Q>: Send, &'output_transaction mut JsonValueTransaction<'output_budget, R, Q>: Send,

§

impl<'input_transaction, 'input_budget, 'output_transaction, 'output_budget, R, Q> Sync for JsonTreeMutator<'input_transaction, 'input_budget, 'output_transaction, 'output_budget, R, Q>
where &'input_transaction mut JsonValueTransaction<'input_budget, R, Q>: Sync, &'output_transaction mut JsonValueTransaction<'output_budget, R, Q>: Sync,

§

impl<'input_transaction, 'input_budget, 'output_transaction, 'output_budget, R, Q> Unpin for JsonTreeMutator<'input_transaction, 'input_budget, 'output_transaction, 'output_budget, R, Q>
where &'input_transaction mut JsonValueTransaction<'input_budget, R, Q>: Unpin, &'output_transaction mut JsonValueTransaction<'output_budget, R, Q>: Unpin,

§

impl<'input_transaction, 'input_budget, 'output_transaction, 'output_budget, R, Q> UnsafeUnpin for JsonTreeMutator<'input_transaction, 'input_budget, 'output_transaction, 'output_budget, R, Q>
where &'input_transaction mut JsonValueTransaction<'input_budget, R, Q>: UnsafeUnpin, &'output_transaction mut JsonValueTransaction<'output_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.