rshyper_core/traits/
nodes.rs

1/*
2    Appellation: nodes <module>
3    Contrib: @FL03
4*/
5use crate::{VertexId, Weight};
6
7/// A trait denoting a node within the hypergraph.
8pub trait HyperNode<Idx> {
9    fn index(&self) -> &VertexId<Idx>;
10}
11
12/// Extends the base [HyperNode] trait with the [`Eq`] and [`Hash`](core::hash::Hash) traits
13/// for use with hash-related structures.
14pub trait HashNode<Idx>: HyperNode<Idx> + Eq + core::hash::Hash {
15    private!();
16}
17
18pub trait Weighted<T> {
19    fn weight(&self) -> &Weight<T>;
20
21    fn weight_mut(&mut self) -> &mut Weight<T>;
22}
23
24/*
25 ************* Implementations *************
26*/
27impl<T> Weighted<T> for T
28where
29    T: AsRef<Weight<T>> + AsMut<Weight<T>>,
30{
31    fn weight(&self) -> &Weight<T> {
32        self.as_ref()
33    }
34
35    fn weight_mut(&mut self) -> &mut Weight<T> {
36        self.as_mut()
37    }
38}
39
40impl<T, Idx> HashNode<Idx> for T
41where
42    T: HyperNode<Idx> + Eq + core::hash::Hash,
43{
44    seal!();
45}
46
47impl<T, Idx> HyperNode<Idx> for T
48where
49    T: core::borrow::Borrow<VertexId<Idx>>,
50{
51    fn index(&self) -> &VertexId<Idx> {
52        self.borrow()
53    }
54}