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
/// Represents the limits of different runtime operations.
#[derive(Debug, Clone, Copy)]
pub struct RuntimeLimits {
/// Max stack size before an error is thrown.
stack_size: usize,
/// Max loop iterations before an error is thrown.
loop_iteration: u64,
/// Max backtrace count in exception.
backtrace_limit: usize,
/// Max function recursion limit
resursion: usize,
}
impl Default for RuntimeLimits {
#[inline]
fn default() -> Self {
Self {
loop_iteration: u64::MAX,
resursion: 512,
backtrace_limit: 50,
stack_size: 1024 * 10,
}
}
}
impl RuntimeLimits {
/// Return the loop iteration limit.
///
/// If the limit is exceeded in a loop it will throw and errror.
///
/// The limit value [`u64::MAX`] means that there is no limit.
#[inline]
#[must_use]
pub const fn loop_iteration_limit(&self) -> u64 {
self.loop_iteration
}
/// Set the loop iteration limit.
///
/// If the limit is exceeded in a loop it will throw and errror.
///
/// Setting the limit to [`u64::MAX`] means that there is no limit.
#[inline]
pub fn set_loop_iteration_limit(&mut self, value: u64) {
self.loop_iteration = value;
}
/// Disable loop iteration limit.
#[inline]
pub fn disable_loop_iteration_limit(&mut self) {
self.loop_iteration = u64::MAX;
}
/// Get max backtrace limit for an exception.
///
/// Default is 50.
#[inline]
#[must_use]
pub const fn backtrace_limit(&self) -> usize {
self.backtrace_limit
}
/// Set max backtrace limit for an exception.
#[inline]
pub fn set_backtrace_limit(&mut self, value: usize) {
self.backtrace_limit = value;
}
/// Get max stack size.
#[inline]
#[must_use]
pub const fn stack_size_limit(&self) -> usize {
self.stack_size
}
/// Set max stack size before an error is thrown.
#[inline]
pub fn set_stack_size_limit(&mut self, value: usize) {
self.stack_size = value;
}
/// Get recursion limit.
#[inline]
#[must_use]
pub const fn recursion_limit(&self) -> usize {
self.resursion
}
/// Set recursion limit before an error is thrown.
#[inline]
pub fn set_recursion_limit(&mut self, value: usize) {
self.resursion = value;
}
}