Skip to main content

swf_builders/services/task/
set.rs

1use super::*;
2
3// ============== SetTaskDefinitionBuilder ==============
4/// Builder for constructing a set task that assigns variables in the workflow state.
5#[derive(Default)]
6pub struct SetTaskDefinitionBuilder {
7    task: SetTaskDefinition,
8}
9
10impl SetTaskDefinitionBuilder {
11    pub fn new() -> Self {
12        Self::default()
13    }
14
15    /// Replaces all set variables with the provided map.
16    pub fn variables(&mut self, vars: HashMap<String, Value>) -> &mut Self {
17        self.task.set = SetValue::Map(vars);
18        self
19    }
20
21    /// Adds or updates a single variable in the set task.
22    pub fn put(&mut self, key: &str, value: Value) -> &mut Self {
23        match &mut self.task.set {
24            SetValue::Map(map) => {
25                map.insert(key.to_string(), value);
26            }
27            _ => {
28                let mut map = HashMap::new();
29                map.insert(key.to_string(), value);
30                self.task.set = SetValue::Map(map);
31            }
32        }
33        self
34    }
35}
36
37impl_task_definition_builder_base!(SetTaskDefinitionBuilder, task, TaskDefinition::Set);