Skip to main content

swf_core/models/task/
flow_directive.rs

1use serde::{Deserialize, Serialize};
2
3/// Represents a typed flow directive that can be an enumerated value or a custom string
4#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5#[serde(untagged)]
6pub enum FlowDirectiveValue {
7    /// One of the standard enumerated flow directives
8    Enumerated(FlowDirectiveType),
9    /// A custom/free-form flow directive string
10    Custom(String),
11}
12
13/// Enumerates the standard flow directive types
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
15pub enum FlowDirectiveType {
16    /// Continues to the next task in the workflow
17    #[serde(rename = "continue")]
18    Continue,
19    /// Exits the current composite task
20    #[serde(rename = "exit")]
21    Exit,
22    /// Ends the workflow execution
23    #[serde(rename = "end")]
24    End,
25}
26
27impl FlowDirectiveValue {
28    /// Checks if this is one of the standard enumerated values
29    pub fn is_enumerated(&self) -> bool {
30        matches!(self, FlowDirectiveValue::Enumerated(_))
31    }
32
33    /// Checks if this flow directive represents a termination (exit or end)
34    pub fn is_termination(&self) -> bool {
35        matches!(
36            self,
37            FlowDirectiveValue::Enumerated(FlowDirectiveType::Exit | FlowDirectiveType::End)
38        )
39    }
40}
41
42impl Default for FlowDirectiveValue {
43    fn default() -> Self {
44        FlowDirectiveValue::Enumerated(FlowDirectiveType::Continue)
45    }
46}