acts_next/model/act/
block.rs1use crate::{Act, Vars};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Default, Clone, Serialize, Deserialize)]
5pub struct Block {
6 #[serde(default)]
7 pub then: Vec<Act>,
8
9 #[serde(default)]
10 pub inputs: Vars,
11
12 #[serde(default)]
13 pub next: Option<Box<Act>>,
14}
15
16impl Block {
17 pub fn new() -> Self {
18 Default::default()
19 }
20
21 pub fn with_input<T>(mut self, name: &str, value: T) -> Self
22 where
23 T: Serialize + Clone,
24 {
25 self.inputs.set(name, value);
26 self
27 }
28
29 pub fn with_next<F: Fn(Act) -> Act>(mut self, build: F) -> Self {
30 self.next = Some(Box::new(build(Act::default())));
31 self
32 }
33
34 pub fn with_then(mut self, build: fn(Vec<Act>) -> Vec<Act>) -> Self {
35 let stmts = Vec::new();
36 self.then = build(stmts);
37 self
38 }
39}
40
41impl From<Block> for Act {
42 fn from(val: Block) -> Self {
43 Act::block(|_| val.clone())
44 }
45}