Skip to main content

qubit_json/value/traverse/
json_tree_context.rs

1// =============================================================================
2//    Copyright (c) 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5//
6//    Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! Defines context supplied with one JSON tree callback.
9
10use super::JsonTreeLocation;
11
12/// Describes the root-inclusive depth and parent location of a JSON node.
13///
14/// # Type Parameters
15///
16/// * `'a` - Lifetime of an object key borrowed from the traversed JSON tree.
17///
18/// # Examples
19///
20/// ```
21/// use qubit_json::value::traverse::JsonTreeContext;
22/// use qubit_json::value::traverse::JsonTreeLocation;
23///
24/// let key = "items";
25/// let context = JsonTreeContext {
26///     depth: 2,
27///     location: JsonTreeLocation::ObjectValue { key },
28/// };
29/// assert_eq!(context.depth, 2);
30/// assert_eq!(context.location, JsonTreeLocation::ObjectValue { key });
31/// ```
32#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
33pub struct JsonTreeContext<'a> {
34    /// Root-inclusive depth; the root is always at depth one.
35    pub depth: usize,
36    /// Root marker or location of this node in its immediate parent.
37    pub location: JsonTreeLocation<'a>,
38}