1use crate::{HasIdentity, HasLabel, NodeId};
17use std::fmt::Debug;
18
19pub trait Place: Debug + HasIdentity + HasLabel {}
29
30pub trait Transition: Debug + HasIdentity + HasLabel {}
36
37pub trait Arc: Debug {
43 fn source(&self) -> NodeId;
44 fn target(&self) -> NodeId;
45}
46
47pub trait Net: Debug {
52 type Place: Place;
53 type Transition: Transition;
54 type Arc: Arc;
55
56 fn places(&self) -> Vec<&Self::Place>;
57 fn place(&self, id: &NodeId) -> Option<&Self::Place>;
58 fn place_mut(&mut self, id: &NodeId) -> Option<&mut Self::Place>;
59 fn add_place(&mut self) -> NodeId;
60 fn add_labeled_place<S>(&mut self, label: S) -> NodeId
61 where
62 S: Into<String>;
63
64 fn transitions(&self) -> Vec<&Self::Transition>;
65 fn transition(&self, id: &NodeId) -> Option<&Self::Transition>;
66 fn transition_mut(&mut self, id: &NodeId) -> Option<&mut Self::Transition>;
67 fn add_transition(&mut self) -> NodeId;
68 fn add_labeled_transition<S>(&mut self, label: S) -> NodeId
69 where
70 S: Into<String>;
71
72 fn arcs(&self) -> Vec<&Self::Arc>;
73 fn add_arc(&mut self, source: NodeId, target: NodeId);
74
75 fn inputs(&self, id: &NodeId) -> Vec<&NodeId>;
76 fn outputs(&self, id: &NodeId) -> Vec<&NodeId>;
77}
78
79pub trait NetBuilder {
87 type Place: Place;
88 type Transition: Transition;
89 type Arc: Arc;
90 type Net: Net<Place = Self::Place, Transition = Self::Transition, Arc = Self::Arc>;
91 type PlaceBuilder: PlaceBuilder<TransitionBuilder = Self::TransitionBuilder>;
92 type TransitionBuilder: TransitionBuilder<PlaceBuilder = Self::PlaceBuilder>;
93
94 fn place(&mut self) -> Self::PlaceBuilder;
95 fn place_with_id(&mut self, id: &NodeId) -> Self::PlaceBuilder;
96 fn recall_place(&mut self, tag: &'static str) -> Self::PlaceBuilder;
97
98 fn transition(&mut self) -> Self::TransitionBuilder;
99 fn transition_with_id(&mut self, id: &NodeId) -> Self::TransitionBuilder;
100 fn recall_transition(&mut self, tag: &'static str) -> Self::TransitionBuilder;
101
102 fn arc(&mut self, source: NodeId, target: NodeId) -> &mut Self;
103
104 fn recall(&self, tag: &'static str) -> Option<NodeId>;
105
106 fn build(self) -> Self::Net;
107}
108
109pub trait PlaceBuilder {
113 type TransitionBuilder: TransitionBuilder;
114
115 fn with_label<S>(self, _label: S) -> Self
116 where
117 S: Into<String>;
118 fn id(&self) -> NodeId;
119
120 fn remember_as(self, tag: &'static str) -> Self;
121
122 fn to_transition(self) -> Self::TransitionBuilder;
123 fn to_id(self, id: &NodeId) -> Self::TransitionBuilder;
124 fn to_remembered(self, tag: &'static str) -> Self::TransitionBuilder;
125
126 #[allow(clippy::wrong_self_convention)]
127 fn from_transition(self) -> Self::TransitionBuilder;
128 #[allow(clippy::wrong_self_convention)]
129 fn from_id(self, id: &NodeId) -> Self::TransitionBuilder;
130 #[allow(clippy::wrong_self_convention)]
131 fn from_remembered(self, tag: &'static str) -> Self::TransitionBuilder;
132}
133
134pub trait TransitionBuilder {
138 type PlaceBuilder: PlaceBuilder;
139
140 fn with_label<S>(self, _label: S) -> Self
141 where
142 S: Into<String>;
143 fn id(&self) -> NodeId;
144
145 fn remember_as(self, tag: &'static str) -> Self;
146
147 fn to_place(self) -> Self::PlaceBuilder;
148 fn to_id(self, id: &NodeId) -> Self::PlaceBuilder;
149 fn to_remembered(self, tag: &'static str) -> Self::PlaceBuilder;
150
151 #[allow(clippy::wrong_self_convention)]
152 fn from_place(self) -> Self::PlaceBuilder;
153 #[allow(clippy::wrong_self_convention)]
154 fn from_id(self, id: &NodeId) -> Self::PlaceBuilder;
155 #[allow(clippy::wrong_self_convention)]
156 fn from_remembered(self, tag: &'static str) -> Self::PlaceBuilder;
157}