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
// SPDX-License-Identifier: Apache-2.0
//! Resource-failure types shared by the budget and [`CodecError`].
//!
//! [`CodecError`]: crate::CodecError
use super::space::SpaceId;
/// Which resource a limit governs.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ResourceDimension {
/// Physical input bytes read at the root.
InputBytes,
/// Bytes produced by decompression.
DecompressedBytes,
/// Bytes retained for the decode session outside expansion output.
RetainedBytes,
/// Admitted semantic or native entities.
Entities,
/// Active recursive nesting depth.
RecursionDepth,
}
/// Why a resource request failed.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ResourceFailure {
/// Policy refused: the request would exceed the allowance.
BudgetExceeded,
/// The allocator refused, surfaced via `try_reserve`.
AllocationFailed,
}
/// An offset qualified by its address space.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SourceLocation {
/// The space the offset indexes.
pub space: SpaceId,
/// The absolute offset within that space.
pub offset: u64,
}
/// A resource refusal.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ResourceLimit {
/// The dimension that refused the request.
pub dimension: ResourceDimension,
/// Whether policy or the allocator refused.
pub reason: ResourceFailure,
/// The allowance in force.
pub limit: u64,
/// The amount already charged before this request.
pub used: u64,
/// The saturating size of the request that failed.
pub additional: u64,
/// The operation that failed, as a static label.
pub operation: &'static str,
}
impl ResourceLimit {
/// Reports an allocator refusal before any resource is charged.
#[must_use]
pub const fn allocation_failed(
dimension: ResourceDimension,
limit: u64,
additional: u64,
operation: &'static str,
) -> Self {
Self {
dimension,
reason: ResourceFailure::AllocationFailed,
limit,
used: 0,
additional,
operation,
}
}
}