1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use crateArity;
use ;
/// [NodeType] is a soft identification for different nodes within a graph or tree structure.
///
/// Most of the time when reading a node's type, we can determine what kind of node it is
/// by the connections around it. For example, in a graph, if a node has 0 incoming connections,
/// it is likely an Input. Inversely, if a node has 0 outgoing connections, it is likely an Output. For
/// a tree, we can tell if it is a leaf or a vertex based on it's nunmber of children. However, when
/// building either a graph or tree, we usually want to specify which type of node we want to create.
/// Thus, we typically use this enum more for writing (building nodes) rather than reading (traversing nodes).
///
/// See the [GraphNode](crate::collections::GraphNode) and [TreeNode](crate::collections::TreeNode)
/// implementations for more details or rules around how this is handled.
///
/// Because of this, the `NodeType` enum is a soft identification, and should be used as a hint rather than a strict rule.
/// The `node_type` method in the `Node` trait has guards around it within the [GraphNode](crate::collections::GraphNode)
/// and [TreeNode](crate::collections::TreeNode) implementations which handle this ambiguity and provide a
/// more accurate node type when traversing the graph or tree. All that being
/// said, it is a very very rare case where the `node_type` method would return a different value than what is
/// specified in the `NodeType` enum - the only way this is possible is if the `NodeType` isn't supplied to
/// the node during creation.
///
/// Within each node (`GraphNode` or `TreeNode`), the [NodeType] is used to determine the validity of the
/// node given the value it holds.
/// Node is a trait that abstracts out common information and behavior needed within the `GraphNode`
/// and `TreeNode` implementations. Both these nodes handle their connections differently, but they share
/// this common interface. Within this crate, we also handle these data structures a little differently
/// than they would usually be defined, so we leave the core implementation up to the struct, and allow
/// this trait to supply the 'radiate' interface for working with nodes.