Skip to main content

JsonTreeMutVisitor

Trait JsonTreeMutVisitor 

Source
pub trait JsonTreeMutVisitor {
    type Error;

    // Required method
    fn visit(
        &mut self,
        value: &mut Value,
        context: JsonTreeContext<'_>,
    ) -> Result<JsonTreeControl, Self::Error>;
}
Expand description

Mutates JSON nodes after the complete input tree has passed admission.

Output admission runs only after every visitor callback succeeds. Returning JsonTreeControl::SkipSubtree skips descendant callbacks but does not skip final output accounting.

§Examples

use qubit_json::value::traverse::{
    JsonTreeContext, JsonTreeControl, JsonTreeMutVisitor,
};
use serde_json::Value;

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

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

let _visitor = Visitor;

Required Associated Types§

Source

type Error

Domain-specific failure returned by this visitor.

Required Methods§

Source

fn visit( &mut self, value: &mut Value, context: JsonTreeContext<'_>, ) -> Result<JsonTreeControl, Self::Error>

Mutates one node and selects whether descendant callbacks run.

§Parameters
  • value - Current node available for mutation.
  • context - Root-relative location and depth of the node.
§Returns

The traversal control decision for descendant callbacks.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§