moduforge_rules_engine/handler/table/
mod.rs

1pub mod zen;
2
3use moduforge_rules_expression::variable::Variable;
4
5#[derive(Debug, Clone)]
6pub(crate) enum RowOutputKind {
7    Variable(Variable),
8}
9
10#[derive(Debug, Default)]
11pub(crate) struct RowOutput {
12    output: OutputMap,
13}
14
15type OutputMap = Vec<(String, RowOutputKind)>;
16
17impl RowOutput {
18    pub fn push<K: Into<String>>(
19        &mut self,
20        key: K,
21        value: RowOutputKind,
22    ) {
23        self.output.push((key.into(), value))
24    }
25
26    pub async fn to_json(&self) -> Variable {
27        let object = Variable::empty_object();
28
29        for (key, kind) in &self.output {
30            match kind {
31                RowOutputKind::Variable(variable) => {
32                    object.dot_insert(key.as_str(), variable.clone());
33                },
34            }
35        }
36
37        object
38    }
39}