acorn_lib/schema/
graph.rs

1use petgraph::stable_graph::NodeIndex;
2use petgraph::visit::EdgeRef;
3use petgraph::{graph::Graph, Direction};
4
5type _Graph = Graph<String, u8>;
6pub fn get_node_from_label(graph: &_Graph, label: &str) -> Option<NodeIndex> {
7    match graph.node_indices().find(|n| graph[*n] == label) {
8        | Some(node) => Some(node),
9        | None => None,
10    }
11}
12pub fn get_node_name(graph: &_Graph, node: NodeIndex) -> Option<String> {
13    match graph.node_weight(node) {
14        | Some(value) => Some(value.to_string()),
15        | None => None,
16    }
17}
18pub fn get_node_parent(graph: &_Graph, node: NodeIndex) -> Option<NodeIndex> {
19    match graph.edges_directed(node, Direction::Incoming).clone().next() {
20        | Some(edge) => Some(edge.source()),
21        | None => None,
22    }
23}