qubit-json 0.13.0

Resource-aware infrastructure for lenient and strict JSON processing
Documentation
// =============================================================================
//    Copyright (c) 2026 Haixing Hu.
//
//    SPDX-License-Identifier: Apache-2.0
//
//    Licensed under the Apache License, Version 2.0.
// =============================================================================
//! One guarded open array or object in a lexical JSON value builder.

use std::collections::BTreeSet;

use crate::value::SafeJsonValue;
use crate::value::internal::SafeValueBuilder;

/// Holds one open JSON container while the value builder processes its
/// children.
///
/// Standard variants accumulate independently protected child values until the
/// closing token arrives. Last-wins variants build directly into protected
/// final containers so replaced members can be safely discarded.
pub(crate) enum JsonValueFrame {
    /// An array whose children are independently protected values.
    Array(
        /// Child values retained while the array is being materialized.
        Vec<SafeJsonValue>,
    ),
    /// Last-wins array constructed directly in its protected final container.
    LastWinsArray(
        /// Builder retaining array children until the closing token arrives.
        SafeValueBuilder,
    ),
    /// An object with a decoded key awaiting its corresponding value.
    Object {
        /// Values accumulated for this object.
        values: Vec<(String, SafeJsonValue)>,
        /// Decoded keys accepted for this object.
        keys: BTreeSet<String>,
        /// Key emitted immediately before the next value.
        pending_key: Option<String>,
    },
    /// Last-wins object constructed directly in its protected final container.
    LastWinsObject {
        /// Protected final map builder.
        values: SafeValueBuilder,
        /// Key emitted immediately before the next value.
        pending_key: Option<String>,
    },
}