use std::{ hash::{Hash, Hasher}, marker::PhantomData, }; use enum_dispatch::enum_dispatch; use petgraph::stable_graph::NodeIndex; // Due to apparent limitations of enum_dispatch we're forced to import some types backwards. #[enum_dispatch] pub trait GetNodeIndex { fn node_index(&self) -> NodeIndex; } #[derive(Debug, Clone, Copy)] pub struct GenericIndex { node_index: NodeIndex, marker: PhantomData, } impl GenericIndex { pub fn new(index: NodeIndex) -> Self { Self { node_index: index, marker: PhantomData, } } } impl Hash for GenericIndex { fn hash(&self, state: &mut H) { self.node_index.hash(state) } } impl PartialEq for GenericIndex { fn eq(&self, other: &Self) -> bool { self.node_index == other.node_index } } impl Eq for GenericIndex {} impl GetNodeIndex for GenericIndex { fn node_index(&self) -> NodeIndex { self.node_index } }