1#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum EdgeTarget {
6 Node(String),
8 End,
10}
11
12impl EdgeTarget {
13 pub fn node(name: impl Into<String>) -> Self {
14 Self::Node(name.into())
15 }
16
17 pub fn end() -> Self {
18 Self::End
19 }
20
21 pub fn is_end(&self) -> bool {
22 matches!(self, Self::End)
23 }
24}
25
26#[derive(Debug, Clone)]
28pub struct Edge {
29 pub from: String,
30 pub to: EdgeTarget,
31}
32
33impl Edge {
34 pub fn new(from: impl Into<String>, to: EdgeTarget) -> Self {
35 Self {
36 from: from.into(),
37 to,
38 }
39 }
40}
41
42#[derive(Clone)]
44pub struct ConditionalEdge {
45 pub from: String,
46 pub router: ConditionalRouter,
47}
48
49pub type ConditionalRouter = std::sync::Arc<dyn Fn(&str) -> EdgeTarget + Send + Sync>;
51
52impl std::fmt::Debug for ConditionalEdge {
53 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54 f.debug_struct("ConditionalEdge")
55 .field("from", &self.from)
56 .field("router", &"<fn>")
57 .finish()
58 }
59}