transit_grid/core/accessability.rs
1use super::NodeId;
2
3/// Enum `Accessability` representing the accessibility of nodes in a network.
4///
5/// This enum has two variants:
6/// * `ReachableNodes`: This variant holds a vector of `NodeId`s which are reachable from a specific node.
7/// This information could be used to limit the search space during network traversal operations.
8///
9/// * `UnreachableNodes`: This variant holds a vector of `NodeId`s which cannot be reached from a specific node.
10/// This information could be used to prevent the search from exploring infeasible paths during network traversal operations.
11///
12/// # Variants
13///
14/// * `ReachableNodes(Vec<NodeId>)`: A variant holding a vector of reachable node IDs.
15///
16/// * `UnreachableNodes(Vec<NodeId>)`: A variant holding a vector of unreachable node IDs.
17///
18/// # Example
19///
20/// ```
21/// use transit_grid::core::{Accessability, NodeId};
22///
23/// // Define some node IDs
24/// let nodes = vec![1, 2, 3, 4, 5];
25///
26/// // Define Accessability
27/// let access = Accessability::ReachableNodes(nodes);
28///
29/// match access {
30/// Accessability::ReachableNodes(ids) => {
31/// // Process reachable nodes
32/// }
33/// Accessability::UnreachableNodes(ids) => {
34/// // Process unreachable nodes
35/// }
36/// }
37/// ```
38#[derive(Clone, Debug, Eq, PartialEq)]
39pub enum Accessability {
40 /// A variant holding a vector of reachable node IDs.
41 ReachableNodes(Vec<NodeId>),
42 /// A variant holding a vector of unreachable node IDs.
43 UnreachableNodes(Vec<NodeId>),
44}
45
46impl Accessability {
47 /// Returns a reference to the vector of reachable nodes if the `NodeAccessability` instance is the `ReachableNodes` variant.
48 ///
49 /// # Returns
50 ///
51 /// `Option<&Vec<NodeId>>` - Some reference to the vector of reachable nodes, or None if the instance is `UnreachableNodes`.
52 pub fn reachable_nodes(&self) -> Option<&Vec<NodeId>> {
53 match self {
54 Accessability::ReachableNodes(nodes) => Some(nodes),
55 _ => None,
56 }
57 }
58
59 /// Returns a reference to the vector of unreachable nodes if the `NodeAccessability` instance is the `UnreachableNodes` variant.
60 ///
61 /// # Returns
62 ///
63 /// `Option<&Vec<NodeId>>` - Some reference to the vector of unreachable nodes, or None if the instance is `ReachableNodes`.
64 pub fn unreachable_nodes(&self) -> Option<&Vec<NodeId>> {
65 match self {
66 Accessability::UnreachableNodes(nodes) => Some(nodes),
67 _ => None,
68 }
69 }
70}
71
72#[cfg(test)]
73mod tests {
74 use super::*;
75
76 #[test]
77 fn test_node_accessibility() {
78 let reachable_nodes = Accessability::ReachableNodes(vec![1, 2, 3]);
79 let unreachable_nodes = Accessability::UnreachableNodes(vec![4, 5, 6]);
80
81 assert_eq!(reachable_nodes.reachable_nodes(), Some(&vec![1, 2, 3]));
82 assert_eq!(reachable_nodes.unreachable_nodes(), None);
83
84 assert_eq!(unreachable_nodes.reachable_nodes(), None);
85 assert_eq!(unreachable_nodes.unreachable_nodes(), Some(&vec![4, 5, 6]));
86 }
87}