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
38
39
40
41
42
43
44
45
46
47
48
49
use crate::*;

/// Save current compiling metadata as snapshot.
pub struct SaveSnapshot;
impl SaveSnapshot {
    /// Save snapshot
    pub fn new() -> Self {
        Self
    }
}
impl Compiler for SaveSnapshot {
    fn compile(&self, ctx: Context) -> CompilerReturn {
        compile!({
            ctx.save_snapshot().await?;
            Ok(ctx)
        })
    }
}

/// Wait specified snapshots' stages.
#[derive(Clone)]
pub struct WaitSnapshot {
    rule_stage_set: Vec<(String, usize)>,
}
impl WaitSnapshot {
    /// Wait until first snapshot created
    pub fn new() -> Self {
        Self {
            rule_stage_set: Vec::new(),
        }
    }
    /// Add wait rule and until
    /// In most cases, until is 1
    pub fn wait(mut self, rule: impl ToString, until: usize) -> Self {
        self.rule_stage_set.push((rule.to_string(), until));
        self
    }
}
impl Compiler for WaitSnapshot {
    fn compile(&self, ctx: Context) -> CompilerReturn {
        let set = self.rule_stage_set.clone();
        compile!({
            for (rule, until) in set {
                ctx.wait_snapshot_until(rule, until).await?
            }
            Ok(ctx)
        })
    }
}