Skip to main content

JsonTreeVisitor

Trait JsonTreeVisitor 

Source
pub trait JsonTreeVisitor {
    type Error;

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

    // Provided method
    fn leave(
        &mut self,
        _value: &Value,
        _context: JsonTreeContext<'_>,
    ) -> Result<(), Self::Error> { ... }
}
Expand description

Receives enter and leave events for budget-admitted JSON tree nodes.

§Examples

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

struct CountingVisitor {
    count: usize,
}
impl JsonTreeVisitor for CountingVisitor {
    type Error = std::convert::Infallible;

    fn enter(
        &mut self,
        _: &Value,
        _: JsonTreeContext<'_>,
    ) -> Result<(), Self::Error> {
        self.count += 1;
        Ok(())
    }
}

let _visitor = CountingVisitor { count: 0 };

Required Associated Types§

Source

type Error

Domain-specific failure returned by this visitor.

Required Methods§

Source

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

Handles a node after its budget admission and before its descendants.

§Parameters
  • value - Admitted node being visited.
  • context - Root-relative location and depth of the node.
§Returns

Ok(()) to continue traversal, or the visitor’s error to stop it.

Provided Methods§

Source

fn leave( &mut self, _value: &Value, _context: JsonTreeContext<'_>, ) -> Result<(), Self::Error>

Handles a node after all of its descendants have been handled.

§Parameters
  • value - Admitted node whose descendants have been visited.
  • context - Root-relative location and depth of the node.
§Returns

Ok(()) to continue traversal, or the visitor’s error to stop it.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§