Skip to main content

qubit_json/value/traverse/
json_tree_location.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 the location of a JSON tree node within its parent.
9
10/// Identifies a materialized JSON node without exposing a domain path model.
11///
12/// # Examples
13///
14/// ```
15/// use qubit_json::value::traverse::JsonTreeLocation;
16///
17/// let location = JsonTreeLocation::ArrayElement { index: 2 };
18/// assert_eq!(location, JsonTreeLocation::ArrayElement { index: 2 });
19/// ```
20#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
21pub enum JsonTreeLocation<'a> {
22    /// The top-level JSON value.
23    Root,
24    /// An array element identified by its zero-based index.
25    ArrayElement {
26        /// Zero-based position in the parent array.
27        index: usize,
28    },
29    /// An object value identified by its associated object key.
30    ObjectValue {
31        /// Key associated with the value in the parent object.
32        key: &'a str,
33    },
34}