Skip to main content

edifact_primitives/
control.rs

1/// Flow control signal returned by handler methods.
2///
3/// Handlers return this to tell the parser whether to continue
4/// processing or stop early.
5#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
6pub enum Control {
7    /// Continue processing the next segment.
8    #[default]
9    Continue,
10    /// Stop processing immediately.
11    Stop,
12}
13
14impl Control {
15    /// Returns `true` if this is `Control::Continue`.
16    pub fn should_continue(&self) -> bool {
17        matches!(self, Self::Continue)
18    }
19
20    /// Returns `true` if this is `Control::Stop`.
21    pub fn should_stop(&self) -> bool {
22        matches!(self, Self::Stop)
23    }
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29
30    #[test]
31    fn test_control_continue() {
32        let c = Control::Continue;
33        assert!(c.should_continue());
34        assert!(!c.should_stop());
35    }
36
37    #[test]
38    fn test_control_stop() {
39        let c = Control::Stop;
40        assert!(c.should_stop());
41        assert!(!c.should_continue());
42    }
43
44    #[test]
45    fn test_control_default_is_continue() {
46        assert_eq!(Control::default(), Control::Continue);
47    }
48
49    #[test]
50    fn test_control_equality() {
51        assert_eq!(Control::Continue, Control::Continue);
52        assert_eq!(Control::Stop, Control::Stop);
53        assert_ne!(Control::Continue, Control::Stop);
54    }
55}