acts_next/model/act/
msg.rs1use crate::{Act, Vars};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Default, Clone, Serialize, Deserialize)]
7pub struct Msg {
8 #[serde(default)]
9 pub tag: String,
10
11 #[serde(default)]
12 pub key: String,
13
14 #[serde(default)]
15 pub inputs: Vars,
16}
17
18impl Msg {
19 pub fn new() -> Self {
20 Default::default()
21 }
22
23 pub fn with_tag(mut self, tag: &str) -> Self {
24 self.tag = tag.to_string();
25 self
26 }
27
28 pub fn with_key(mut self, key: &str) -> Self {
29 self.key = key.to_string();
30 self
31 }
32
33 pub fn with_input<T>(mut self, name: &str, value: T) -> Self
34 where
35 T: Serialize + Clone,
36 {
37 self.inputs.set(name, value);
38 self
39 }
40}
41
42impl From<Msg> for Act {
43 fn from(val: Msg) -> Self {
44 Act::msg(|_| val.clone())
45 }
46}