Skip to main content

camel_api/
loop_eip.rs

1use crate::filter::FilterPredicate;
2
3/// How the loop terminates.
4#[derive(Clone)]
5pub enum LoopMode {
6    /// Fixed iteration count.
7    Count(usize),
8    /// While a runtime predicate evaluates to true.
9    While(FilterPredicate),
10}
11
12impl std::fmt::Debug for LoopMode {
13    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14        match self {
15            LoopMode::Count(n) => write!(f, "Count({n})"),
16            LoopMode::While(_) => write!(f, "While(<predicate>)"),
17        }
18    }
19}
20
21#[derive(Clone, Debug)]
22pub struct LoopConfig {
23    pub mode: LoopMode,
24}
25
26impl LoopConfig {
27    pub fn new(mode: LoopMode) -> Self {
28        Self { mode }
29    }
30
31    pub fn mode_name(&self) -> &'static str {
32        match &self.mode {
33            LoopMode::Count(_) => "count",
34            LoopMode::While(_) => "while",
35        }
36    }
37}
38
39/// Maximum iterations for while-mode loops. Prevents infinite loops.
40pub const MAX_LOOP_ITERATIONS: usize = 10_000;