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 81 82 83 84 85 86 87
use super::NodeId;
/// Enum `Accessability` representing the accessibility of nodes in a network.
///
/// This enum has two variants:
/// * `ReachableNodes`: This variant holds a vector of `NodeId`s which are reachable from a specific node.
/// This information could be used to limit the search space during network traversal operations.
///
/// * `UnreachableNodes`: This variant holds a vector of `NodeId`s which cannot be reached from a specific node.
/// This information could be used to prevent the search from exploring infeasible paths during network traversal operations.
///
/// # Variants
///
/// * `ReachableNodes(Vec<NodeId>)`: A variant holding a vector of reachable node IDs.
///
/// * `UnreachableNodes(Vec<NodeId>)`: A variant holding a vector of unreachable node IDs.
///
/// # Example
///
/// ```
/// use transit_grid::core::{Accessability, NodeId};
///
/// // Define some node IDs
/// let nodes = vec![1, 2, 3, 4, 5];
///
/// // Define Accessability
/// let access = Accessability::ReachableNodes(nodes);
///
/// match access {
/// Accessability::ReachableNodes(ids) => {
/// // Process reachable nodes
/// }
/// Accessability::UnreachableNodes(ids) => {
/// // Process unreachable nodes
/// }
/// }
/// ```
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Accessability {
/// A variant holding a vector of reachable node IDs.
ReachableNodes(Vec<NodeId>),
/// A variant holding a vector of unreachable node IDs.
UnreachableNodes(Vec<NodeId>),
}
impl Accessability {
/// Returns a reference to the vector of reachable nodes if the `NodeAccessability` instance is the `ReachableNodes` variant.
///
/// # Returns
///
/// `Option<&Vec<NodeId>>` - Some reference to the vector of reachable nodes, or None if the instance is `UnreachableNodes`.
pub fn reachable_nodes(&self) -> Option<&Vec<NodeId>> {
match self {
Accessability::ReachableNodes(nodes) => Some(nodes),
_ => None,
}
}
/// Returns a reference to the vector of unreachable nodes if the `NodeAccessability` instance is the `UnreachableNodes` variant.
///
/// # Returns
///
/// `Option<&Vec<NodeId>>` - Some reference to the vector of unreachable nodes, or None if the instance is `ReachableNodes`.
pub fn unreachable_nodes(&self) -> Option<&Vec<NodeId>> {
match self {
Accessability::UnreachableNodes(nodes) => Some(nodes),
_ => None,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_node_accessibility() {
let reachable_nodes = Accessability::ReachableNodes(vec![1, 2, 3]);
let unreachable_nodes = Accessability::UnreachableNodes(vec![4, 5, 6]);
assert_eq!(reachable_nodes.reachable_nodes(), Some(&vec![1, 2, 3]));
assert_eq!(reachable_nodes.unreachable_nodes(), None);
assert_eq!(unreachable_nodes.reachable_nodes(), None);
assert_eq!(unreachable_nodes.unreachable_nodes(), Some(&vec![4, 5, 6]));
}
}