1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// =============================================================================
// Copyright (c) 2026 Haixing Hu.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0.
// =============================================================================
//! Defines callbacks for mutable JSON tree processing.
use Value;
use JsonTreeContext;
use JsonTreeControl;
/// 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 mut visitor = Visitor;
/// let mut value = Value::Bool(true);
/// let context = JsonTreeContext {
/// depth: 1,
/// location: qubit_json::value::traverse::JsonTreeLocation::Root,
/// };
/// let control = visitor.visit(&mut value, context).unwrap();
/// assert_eq!(value, Value::Null);
/// assert_eq!(control, JsonTreeControl::SkipSubtree);
/// ```