const DEFAULT_BYTE_BUDGET: usize = 16_777_216;
pub const DEFAULT_MAX_STEPS: StepLimit = StepLimit::new(1_000_000);
pub const DEFAULT_MAX_STATE_LEN: StateByteLimit = StateByteLimit::new(DEFAULT_BYTE_BUDGET);
pub const DEFAULT_MAX_RETURN_LEN: ReturnByteLimit = ReturnByteLimit::new(DEFAULT_BYTE_BUDGET);
pub const DEFAULT_MAX_TRACE_SNAPSHOT_LEN: TraceSnapshotByteLimit =
TraceSnapshotByteLimit::new(DEFAULT_BYTE_BUDGET);
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct StepLimit {
value: usize,
}
impl StepLimit {
#[must_use]
pub const fn new(value: usize) -> Self {
Self { value }
}
#[must_use]
pub const fn get(self) -> usize {
self.value
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct StateByteLimit {
value: usize,
}
impl StateByteLimit {
#[must_use]
pub const fn new(value: usize) -> Self {
Self { value }
}
#[must_use]
pub const fn get(self) -> usize {
self.value
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ReturnByteLimit {
value: usize,
}
impl ReturnByteLimit {
#[must_use]
pub const fn new(value: usize) -> Self {
Self { value }
}
#[must_use]
pub const fn get(self) -> usize {
self.value
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TraceSnapshotByteLimit {
value: usize,
}
impl TraceSnapshotByteLimit {
#[must_use]
pub const fn new(value: usize) -> Self {
Self { value }
}
#[must_use]
pub const fn get(self) -> usize {
self.value
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct StepCount {
value: usize,
}
impl StepCount {
pub(crate) const ZERO: Self = Self { value: 0 };
#[must_use]
pub const fn get(self) -> usize {
self.value
}
pub(crate) fn checked_next(self) -> Option<Self> {
let value = self.value.checked_add(1)?;
Some(Self { value })
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct RunLimits {
steps: StepLimit,
state_len: StateByteLimit,
return_len: ReturnByteLimit,
}
impl RunLimits {
#[must_use]
pub const fn new(
max_steps: StepLimit,
max_state_len: StateByteLimit,
max_return_len: ReturnByteLimit,
) -> Self {
Self {
steps: max_steps,
state_len: max_state_len,
return_len: max_return_len,
}
}
#[must_use]
pub const fn step_limit(self) -> StepLimit {
self.steps
}
#[must_use]
pub const fn state_byte_limit(self) -> StateByteLimit {
self.state_len
}
#[must_use]
pub const fn return_byte_limit(self) -> ReturnByteLimit {
self.return_len
}
#[must_use]
pub const fn with_step_limit(mut self, max_steps: StepLimit) -> Self {
self.steps = max_steps;
self
}
#[must_use]
pub const fn with_state_byte_limit(mut self, max_state_len: StateByteLimit) -> Self {
self.state_len = max_state_len;
self
}
#[must_use]
pub const fn with_return_byte_limit(mut self, max_return_len: ReturnByteLimit) -> Self {
self.return_len = max_return_len;
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TraceSnapshotLimits {
run: RunLimits,
snapshot: TraceSnapshotByteLimit,
}
impl TraceSnapshotLimits {
#[must_use]
pub const fn new(run_limits: RunLimits, snapshot_byte_limit: TraceSnapshotByteLimit) -> Self {
Self {
run: run_limits,
snapshot: snapshot_byte_limit,
}
}
#[must_use]
pub const fn run_limits(self) -> RunLimits {
self.run
}
#[must_use]
pub const fn snapshot_byte_limit(self) -> TraceSnapshotByteLimit {
self.snapshot
}
}