qubit_json/decode/json_materialization_error_reason.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//! Structured reasons for failures while materializing unique-key or bounded
9//! last-wins JSON values.
10
11/// Describes why an admitted document could not be materialized as a
12/// duplicate-rejecting unique-key value or a bounded last-wins value.
13///
14/// The reason is available independently of diagnostic source retention and
15/// never contains input-derived text.
16///
17/// # Examples
18///
19/// ```
20/// use qubit_json::decode::JsonMaterializationErrorReason;
21///
22/// let reason = JsonMaterializationErrorReason::DuplicateKey;
23/// assert_eq!(reason, JsonMaterializationErrorReason::DuplicateKey);
24/// ```
25#[non_exhaustive]
26#[must_use]
27#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
28pub enum JsonMaterializationErrorReason {
29 /// A decoded object key appeared more than once.
30 DuplicateKey,
31 /// Historical compatibility reason; the shared builder no longer produces
32 /// it. Current root-inclusive `max_depth` rejection is reported as a
33 /// budget error during lexical admission.
34 DepthLimit {
35 /// Historical maximum number of nested containers accepted during
36 /// construction.
37 limit: usize,
38 },
39 /// The bounded last-wins builder encountered more simultaneously open
40 /// containers than configured. The associated decode error points to the
41 /// opening byte of the first over-limit container, unless a later syntax
42 /// or budget failure takes precedence.
43 ContainerLimit {
44 /// Maximum number of simultaneously open containers accepted.
45 limit: usize,
46 },
47 /// An admitted number could not be represented by the intermediate tree.
48 InvalidNumber,
49}