comtrya_lib/atoms/
mod.rs

1pub mod command;
2pub mod directory;
3pub mod file;
4pub mod git;
5pub mod http;
6
7pub enum SideEffect {}
8
9pub struct Outcome {
10    pub side_effects: Vec<SideEffect>,
11    pub should_run: bool,
12}
13
14pub trait Atom: std::fmt::Display {
15    // Determine if this atom needs to run
16    fn plan(&self) -> anyhow::Result<Outcome>;
17
18    // Apply new to old
19    fn execute(&mut self) -> anyhow::Result<()>;
20
21    // These methods allow for finalizers to query the outcome of the Atom.
22    // We'll provide default implementations to allow Atoms to opt in to
23    // the queries that make sense for them
24    fn output_string(&self) -> String {
25        String::from("")
26    }
27
28    fn error_message(&self) -> String {
29        String::from("")
30    }
31
32    fn status_code(&self) -> i32 {
33        0
34    }
35}
36
37pub struct Echo(pub &'static str);
38
39impl Atom for Echo {
40    fn plan(&self) -> anyhow::Result<Outcome> {
41        Ok(Outcome {
42            side_effects: vec![],
43            should_run: true,
44        })
45    }
46
47    fn execute(&mut self) -> anyhow::Result<()> {
48        Ok(())
49    }
50
51    fn output_string(&self) -> String {
52        self.0.to_string()
53    }
54}
55
56impl std::fmt::Display for Echo {
57    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
58        write!(f, "Echo: {}", self.0)
59    }
60}