pedant_graph/containment.rs
1//! The logical hierarchy relation, separate from every other edge.
2
3use serde::Serialize;
4
5use crate::id::GraphNodeId;
6
7/// One logical-ownership edge between a parent node and the node it owns.
8///
9/// Containment is the sole hierarchy relation and never appears in
10/// [`crate::CodeGraph::edges`]: a reference graph may be cyclic and
11/// hub-dominated while the hierarchy stays a clean forest.
12#[derive(Serialize, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
13pub struct ContainmentEdge {
14 parent: GraphNodeId,
15 child: GraphNodeId,
16}
17
18impl ContainmentEdge {
19 pub(crate) fn new(parent: GraphNodeId, child: GraphNodeId) -> Self {
20 Self { parent, child }
21 }
22
23 /// The node that logically owns the child.
24 pub fn parent(&self) -> GraphNodeId {
25 self.parent
26 }
27
28 /// The owned node.
29 pub fn child(&self) -> GraphNodeId {
30 self.child
31 }
32}