mermaid_markdown_api/objects/
node.rs1use crate::objects::connection::Connection;
2use crate::objects::DiagramObject;
3use crate::syntax::CoreSyntaxFunctions;
4use std::collections::VecDeque;
5use strum_macros::AsRefStr;
6
7#[derive(AsRefStr, Debug)]
8pub enum ScopeType {
9 Private,
10 Public,
11 Trait,
12 Payable,
13 Contract,
14 Initializer,
15}
16
17#[derive(AsRefStr, Debug)]
18pub enum ActionType {
19 None,
20 Mutation,
21 View,
22 Process,
23 Event,
24}
25
26pub struct Node {
27 pub name: String,
28 pub scope: ScopeType,
29 pub action: ActionType,
30 pub connections: Vec<Connection>,
31}
32
33impl<T: CoreSyntaxFunctions> DiagramObject<T> for Node {
34 fn add_object_to_schema(
35 &self,
36 schema: &mut T,
37 id: Option<&str>,
38 _extra_length_num: Option<u8>,
39 ) {
40 let config = schema.build_node_config(self, id);
41 schema.add_node(config);
42 }
43}
44
45impl Node {
46 fn parse_node(
47 &self,
48 schema: &mut impl CoreSyntaxFunctions,
49 ) {
50 for connection in &self.connections {
51 self.add_object_to_schema(schema, None, None);
52 connection.add_object_to_schema(schema, None, None);
53 connection.node.add_object_to_schema(schema, None, None);
54 schema.add_linebreak(None);
55 }
56 }
57 pub fn traverse(
58 &self,
59 schema: &mut impl CoreSyntaxFunctions,
60 ) {
61 let mut queue = VecDeque::new();
62 queue.push_back(self);
63
64 while let Some(node) = queue.pop_front() {
65 node.parse_node(schema);
66 for connection in &node.connections {
67 queue.push_back(&connection.node);
68 }
69 }
70 }
71}