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
/// Represents the limits of different runtime operations.
#[derive(Debug, Clone, Copy)]
pub struct RuntimeLimits {
/// Max stack size before an error is thrown.
stack_size_limit: usize,
/// Max loop iterations before an error is thrown.
loop_iteration_limit: u64,
/// Max function recursion limit
resursion_limit: usize,
}
impl Default for RuntimeLimits {
#[inline]
fn default() -> Self {
Self {
loop_iteration_limit: u64::MAX,
resursion_limit: 512,
stack_size_limit: 1024,
}
}
}
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_limit
}
/// 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_limit = value;
}
/// Disable loop iteration limit.
#[inline]
pub fn disable_loop_iteration_limit(&mut self) {
self.loop_iteration_limit = u64::MAX;
}
/// Get max stack size.
#[inline]
#[must_use]
pub const fn stack_size_limit(&self) -> usize {
self.stack_size_limit
}
/// Set max stack size before an error is thrown.
#[inline]
pub fn set_stack_size_limit(&mut self, value: usize) {
self.stack_size_limit = value;
}
/// Get recursion limit.
#[inline]
#[must_use]
pub const fn recursion_limit(&self) -> usize {
self.resursion_limit
}
/// Set recursion limit before an error is thrown.
#[inline]
pub fn set_recursion_limit(&mut self, value: usize) {
self.resursion_limit = value;
}
}