graph_api_lib/
label.rs

1use crate::Index;
2use std::fmt::Debug;
3use std::hash::Hash;
4
5/// A label for an `Element`. This can be either a vertex or an edge.
6pub trait Label
7where
8    Self: Sized + Copy + Eq + Hash + Debug,
9{
10    /// Information about indexes for this label
11    type Index: Eq + Copy + Hash + Debug + Index + 'static;
12
13    /// All label variants
14    fn variants() -> &'static [Self];
15
16    /// The indexes associated with this label
17    fn indexes(&self) -> &'static [Self::Index];
18
19    /// A unique ordinal for this label
20    fn ordinal(&self) -> usize;
21
22    /// The name of the label
23    fn name(&self) -> &'static str;
24}
25
26impl Label for () {
27    type Index = ();
28
29    /// The anonymous label
30    fn variants() -> &'static [Self] {
31        &[()]
32    }
33
34    fn indexes(&self) -> &'static [Self::Index] {
35        &[]
36    }
37
38    fn ordinal(&self) -> usize {
39        0
40    }
41
42    fn name(&self) -> &'static str {
43        "<anonymous>"
44    }
45}