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
use crate::atoms::Atom;

mod output_contains;
pub use output_contains::OutputContains;

#[allow(dead_code)]
pub enum FlowControl {
    StopIf(Box<dyn Finalizer>),
}

/// Finalizers allow us to store data within the manifests KV store,
/// or to end the execution of atoms for the action
pub trait Finalizer {
    fn finalize(&self, atom: &dyn Atom) -> anyhow::Result<bool>;
}

#[cfg(test)]
pub mod test {
    use super::*;
    use anyhow::anyhow;

    pub struct EchoFinalizer(pub bool);

    impl Finalizer for EchoFinalizer {
        fn finalize(&self, _atom: &dyn Atom) -> anyhow::Result<bool> {
            Ok(self.0)
        }
    }

    pub struct ErrorFinalizer();

    impl Finalizer for ErrorFinalizer {
        fn finalize(&self, _atom: &dyn Atom) -> anyhow::Result<bool> {
            Err(anyhow!("ErrorFinalizer"))
        }
    }
}