rs_graph/
attributes.rs

1/*
2 * Copyright (c) 2018-2021 Frank Fischer <frank-fischer@shadow-soft.de>
3 *
4 * This program is free software: you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program.  If not, see  <http://www.gnu.org/licenses/>
16 */
17
18//! Extend a graph with attributes.
19//!
20//! Sometimes one needs additional attributes associated with the nodes or edges of a graph.
21//! This module provides some traits to access associated node and edge attributes if the graph
22//! type supports them.
23use crate::traits::Graph;
24
25/// Object with associated node attributes.
26pub trait NodeAttributes<G, Attr>
27where
28    G: Graph,
29{
30    // Return the attributes associated with a node.
31    fn node(&self, u: G::Node<'_>) -> &Attr;
32
33    // Return mutable attributes associated with a node.
34    fn node_mut(&mut self, u: G::Node<'_>) -> &mut Attr;
35}
36
37/// Object with associated edge attributes.
38pub trait EdgeAttributes<G, Attr>
39where
40    G: Graph,
41{
42    // Return the attributes associated with an edge.
43    fn edge(&self, e: G::Edge<'_>) -> &Attr;
44
45    // Return mutable attributes associated with an node.
46    fn edge_mut(&mut self, e: G::Edge<'_>) -> &mut Attr;
47}
48
49/// A trait to split the graph and its attributes.
50pub trait AttributedGraph {
51    type Graph;
52    type Attributes<'a>
53    where
54        Self: 'a;
55
56    fn split(&mut self) -> (&Self::Graph, Self::Attributes<'_>);
57}