maplibre/render/graph/edge.rs
1use super::NodeId;
2
3/// An edge, which connects two [`Nodes`](super::Node) in
4/// a [`RenderGraph`](crate::render_graph::RenderGraph).
5///
6/// They are used to describe the ordering (which node has to run first)
7/// and may be of two kinds: [`NodeEdge`](Self::NodeEdge) and [`SlotEdge`](Self::SlotEdge).
8///
9/// Edges are added via the `render_graph::add_node_edge(output_node, input_node)` and the
10/// `render_graph::add_slot_edge(output_node, output_slot, input_node, input_slot)` methods.
11///
12/// The former simply states that the `output_node` has to be run before the `input_node`,
13/// while the later connects an output slot of the `output_node`
14/// with an input slot of the `input_node` to pass additional data along.
15/// For more information see [`SlotType`](super::SlotType).
16#[derive(Clone, Debug, Eq, PartialEq)]
17pub enum Edge {
18 /// An edge describing to ordering of both nodes (`output_node` before `input_node`)
19 /// and connecting the output slot at the `output_index` of the output_node
20 /// with the slot at the `input_index` of the `input_node`.
21 SlotEdge {
22 input_node: NodeId,
23 input_index: usize,
24 output_node: NodeId,
25 output_index: usize,
26 },
27 /// An edge describing to ordering of both nodes (`output_node` before `input_node`).
28 NodeEdge {
29 input_node: NodeId,
30 output_node: NodeId,
31 },
32}
33
34impl Edge {
35 /// Returns the id of the `input_node`.
36 pub fn get_input_node(&self) -> NodeId {
37 match self {
38 Edge::SlotEdge { input_node, .. } => *input_node,
39 Edge::NodeEdge { input_node, .. } => *input_node,
40 }
41 }
42
43 /// Returns the id of the `output_node`.
44 pub fn get_output_node(&self) -> NodeId {
45 match self {
46 Edge::SlotEdge { output_node, .. } => *output_node,
47 Edge::NodeEdge { output_node, .. } => *output_node,
48 }
49 }
50}
51
52#[derive(PartialEq, Eq)]
53pub enum EdgeExistence {
54 Exists,
55 DoesNotExist,
56}