qubit_json/decode/json_validated_limit.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//! Additional validated decoding limits.
9
10/// Identifies an additional per-document decode limit for validated JSON.
11///
12/// The decoder reports this value in
13/// [`JsonValidatedDecodeError::Limit`](crate::decode::JsonValidatedDecodeError::Limit)
14/// when a configured value or encoded-string bound is exceeded.
15///
16/// # Examples
17///
18/// ```
19/// use std::convert::Infallible;
20///
21/// use qubit_json::decode::JsonDecoder;
22/// use qubit_json::decode::JsonNumberPolicy;
23/// use qubit_json::decode::JsonValidatedDecodeError;
24/// use qubit_json::decode::JsonValidatedDecodeOptions;
25/// use qubit_json::decode::JsonValidatedLimit;
26///
27/// let options = JsonValidatedDecodeOptions::builder()
28/// .max_value_and_key_nodes(2)
29/// .build();
30/// let error = JsonDecoder::unlimited()
31/// .decode_unique_validated_str("{\"key\":1}", &options, |_, _| {
32/// Ok::<_, Infallible>(JsonNumberPolicy::Preserve)
33/// })
34/// .expect_err("the object, key, and value exceed the two-node limit");
35/// assert!(matches!(
36/// error,
37/// JsonValidatedDecodeError::Limit {
38/// limit: JsonValidatedLimit::ValueAndKeyNodes,
39/// ..
40/// }
41/// ));
42/// ```
43#[non_exhaustive]
44#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
45pub enum JsonValidatedLimit {
46 /// Value entries plus decoded object-key entries.
47 ValueAndKeyNodes,
48 /// Source bytes inside one encoded string token, excluding quotes.
49 EncodedStringBytes,
50}