1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// =============================================================================
// Copyright (c) 2026 Haixing Hu.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0.
// =============================================================================
//! Defines the safe error returned when JCS working memory exceeds its limit.
use Error;
use fmt;
/// Reports when JCS rendering needs more auxiliary memory than the configured
/// limit.
///
/// The error records both byte counts without exposing the rendered value.
///
/// # Examples
///
/// ```
/// use qubit_budget::json::JsonEncodeLimits;
/// use qubit_json::encode::JcsEncoder;
///
/// let limits: JsonEncodeLimits = JsonEncodeLimits::new();
/// let mut encoder = JcsEncoder::with_limits(limits, 0);
/// let error = encoder
/// .to_vec(&serde_json::json!({"key": "value"}))
/// .expect_err("zero working memory cannot render an object");
/// let memory_error = error
/// .working_memory_error()
/// .expect("the failure is caused by the working memory limit");
/// assert_eq!(memory_error.limit(), 0);
/// assert!(memory_error.requested() > memory_error.limit());
/// ```