mcai_graph/
link.rs

1use crate::node::Node;
2use mcai_types::Coordinates;
3use std::cell::Ref;
4
5#[derive(Clone, Copy, Debug, PartialEq)]
6pub enum LinkType {
7  Parentage,
8  Requirement,
9}
10
11#[derive(Clone, Debug, PartialEq)]
12pub struct Link {
13  start_node_id: u32,
14  end_node_id: u32,
15  start: Coordinates,
16  end: Coordinates,
17  kind: LinkType,
18}
19
20impl Link {
21  pub fn new(
22    start_node_id: u32,
23    end_node_id: u32,
24    start: Coordinates,
25    end: Coordinates,
26    kind: LinkType,
27  ) -> Self {
28    Self {
29      start_node_id,
30      end_node_id,
31      start,
32      end,
33      kind,
34    }
35  }
36
37  pub fn start_node_id(&self) -> u32 {
38    self.start_node_id
39  }
40
41  pub fn end_node_id(&self) -> u32 {
42    self.end_node_id
43  }
44
45  pub fn start(&self) -> Coordinates {
46    self.start.clone()
47  }
48
49  pub fn end(&self) -> Coordinates {
50    self.end.clone()
51  }
52
53  pub fn kind(&self) -> LinkType {
54    self.kind
55  }
56}
57
58impl From<(&Node, Ref<'_, Node>, LinkType)> for Link {
59  fn from((from, to, kind): (&Node, Ref<Node>, LinkType)) -> Self {
60    Link::new(
61      from.id(),
62      to.id(),
63      from.get_input_coordinates(),
64      to.get_output_coordinates(),
65      kind,
66    )
67  }
68}