rshyper/traits/
nodes.rs

1/*
2    Appellation: nodes <module>
3    Contrib: @FL03
4*/
5
6/// A trait denoting a node within the hypergraph.
7pub trait HyperNode<Idx> {
8    fn index(&self) -> &crate::Index<Idx>;
9}
10
11/// Extends the base [HyperNode] trait with the [core::cmp::Eq] and [core::hash::Hash] traits
12/// for use with hash-related structures.
13pub trait HashNode<Idx>: HyperNode<Idx> + core::cmp::Eq + core::hash::Hash {}
14
15pub trait Weighted<Idx>: HyperNode<Idx> {
16    type Data;
17
18    fn weight(&self) -> &Self::Data;
19}
20
21/*
22 ************* Implementations *************
23*/
24impl<T, Idx> HyperNode<Idx> for T
25where
26    T: crate::Indexable<Idx>,
27{
28    fn index(&self) -> &crate::Index<Idx> {
29        self.index()
30    }
31}
32impl<T, Idx> HashNode<Idx> for T where T: HyperNode<Idx> + core::cmp::Eq + core::hash::Hash {}