ic_wire/limits.rs
1/// Consumer-selected Serde traversal allowances.
2///
3/// Custom Serde code is trusted: work and allocation outside visited values
4/// cannot be constrained by these allowances. Allocation is conservative
5/// accounting, not a live-heap cap, and depends on target type layouts.
6#[derive(Clone, Copy, Debug)]
7pub struct Limits {
8 /// Maximum encoded/input bytes, including the header when framed.
9 pub bytes: usize,
10 /// Reserve all configured bytes, then eight times visited value sizes and
11 /// byte/text spans. Borrowed spans pay the same charge as owned spans.
12 pub allocation: usize,
13 /// Maximum visits, including seed visits and zero-sized values.
14 pub nodes: usize,
15 /// Maximum visit depth, starting at one.
16 pub depth: usize,
17}
18
19impl Limits {
20 pub(crate) fn without_prefix(self, prefix: usize) -> Result<Self, crate::Error> {
21 Ok(Self {
22 bytes: self.bytes.checked_sub(prefix).ok_or(crate::Error::Limit)?,
23 allocation: self
24 .allocation
25 .checked_sub(prefix)
26 .ok_or(crate::Error::Limit)?,
27 ..self
28 })
29 }
30}