rshyper_core/traits/indexed.rs
1/*
2 Appellation: indexed <module>
3 Contrib: @FL03
4*/
5
6/// This trait is used to denote a type that is aware of its own index.
7pub trait Indexed<T> {
8 type Idx<I>;
9
10 /// Returns the index of the node.
11 fn index(&self) -> &Self::Idx<T>;
12}
13
14/*
15 ************* Implementations *************
16*/
17use crate::VertexId;
18use crate::node::Node;
19
20impl<T> Indexed<T> for VertexId<T> {
21 type Idx<I> = VertexId<I>;
22
23 fn index(&self) -> &Self::Idx<T> {
24 self
25 }
26}
27
28impl<T, Idx> Indexed<Idx> for Node<T, Idx> {
29 type Idx<I> = VertexId<I>;
30
31 fn index(&self) -> &Self::Idx<Idx> {
32 &self.index
33 }
34}