Skip to main content

swf_core/models/task/
set_task.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3use std::collections::HashMap;
4
5use super::TaskDefinitionFields;
6
7/// Represents the value that can be set in a Set task - either a map or a runtime expression string
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9#[serde(untagged)]
10pub enum SetValue {
11    /// A map of key-value pairs to set
12    Map(HashMap<String, Value>),
13    /// A runtime expression string that evaluates to the data to set
14    Expression(String),
15}
16
17impl Default for SetValue {
18    fn default() -> Self {
19        SetValue::Map(HashMap::new())
20    }
21}
22
23/// Represents the definition of a task used to set data
24#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
25pub struct SetTaskDefinition {
26    /// Gets/sets the data to set
27    #[serde(rename = "set")]
28    pub set: SetValue,
29
30    /// Gets/sets the task's common fields
31    #[serde(flatten)]
32    pub common: TaskDefinitionFields,
33}