acts_next/model/act/
if.rs1use crate::Act;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Default, Clone, Serialize, Deserialize)]
5pub struct If {
6 #[serde(default)]
7 pub on: String,
8
9 #[serde(default)]
10 pub then: Vec<Act>,
11
12 #[serde(default)]
13 pub r#else: Vec<Act>,
14}
15
16impl If {
17 pub fn new() -> Self {
18 Default::default()
19 }
20
21 pub fn with_on(mut self, on: &str) -> Self {
22 self.on = on.to_string();
23 self
24 }
25
26 pub fn with_then(mut self, build: fn(Vec<Act>) -> Vec<Act>) -> Self {
27 let stmts = Vec::new();
28 self.then = build(stmts);
29 self
30 }
31
32 pub fn with_else(mut self, build: fn(Vec<Act>) -> Vec<Act>) -> Self {
33 let stmts = Vec::new();
34 self.r#else = build(stmts);
35 self
36 }
37}
38
39impl From<If> for Act {
40 fn from(val: If) -> Self {
41 Act::r#if(|_| val.clone())
42 }
43}