python_to_mermaid/
flowchart.rs

1#[derive(Debug, Clone)]
2pub struct Flowchart {
3    pub is_root: bool,
4    pub begin: String,
5    pub end: String,
6    pub items: Vec<FlowchartItem>,
7}
8
9impl Flowchart {
10    pub fn new_root(label: impl AsRef<str>) -> Self {
11        let label = label.as_ref();
12
13        Self {
14            is_root: true,
15            begin: format!("Begin: {label}"),
16            end: format!("End: {label}"),
17            items: Vec::new(),
18        }
19    }
20
21    pub fn new_sub(label: impl AsRef<str>) -> Self {
22        let label = label.as_ref();
23
24        Self {
25            is_root: false,
26            begin: format!("Begin: {label}"),
27            end: format!("End: {label}"),
28            items: Vec::new(),
29        }
30    }
31
32    pub fn new_unlabeled_sub() -> Self {
33        Self {
34            is_root: false,
35            begin: "Begin".to_string(),
36            end: "End".to_string(),
37            items: Vec::new(),
38        }
39    }
40}
41
42#[derive(Debug, Clone)]
43pub enum FlowchartItem {
44    Step(Step),
45    Condition(Condition),
46    Continue(Continue),
47    Break(Break),
48    Terminal(Terminal),
49    SubFlowchart(Flowchart),
50}
51
52#[derive(Debug, Clone)]
53pub struct Step {
54    pub label: String,
55}
56
57impl Step {
58    pub fn new(label: impl Into<String>) -> Self {
59        Self {
60            label: label.into(),
61        }
62    }
63}
64
65#[derive(Debug, Clone)]
66pub struct Condition {
67    pub condition: String,
68    pub then_items: Vec<FlowchartItem>,
69    pub else_items: Vec<FlowchartItem>,
70}
71
72impl Condition {
73    pub fn new(condition: impl Into<String>) -> Self {
74        Self {
75            condition: condition.into(),
76            then_items: Vec::new(),
77            else_items: Vec::new(),
78        }
79    }
80}
81
82#[derive(Debug, Clone)]
83pub struct Continue {
84    pub label: String,
85}
86
87impl Continue {
88    pub fn new(label: impl Into<String>) -> Self {
89        Self {
90            label: label.into(),
91        }
92    }
93}
94
95#[derive(Debug, Clone)]
96pub struct Break {
97    pub label: String,
98}
99
100impl Break {
101    pub fn new(label: impl Into<String>) -> Self {
102        Self {
103            label: label.into(),
104        }
105    }
106}
107
108#[derive(Debug, Clone)]
109pub struct Terminal {
110    pub label: String,
111}
112
113impl Terminal {
114    pub fn new(label: impl Into<String>) -> Self {
115        Self {
116            label: label.into(),
117        }
118    }
119}