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