This create provides automatic graph derivations.
In order to automatically implement graph traits for
a struct that contains the actual graph data structure in a field,
add #[derive(Graph)] to the struct. The field containing the graph
must either be named graph or be attributed with #[graph].
All graph traits (Graph, Digraph, Network, IndexGraph and
IndexNetwork) that are implemented for the nested graph, are
implemented for the annotated struct, too.
Example
extern crate rs_graph;
#[macro_use]
extern crate rs_graph_derive;
use rs_graph::{Graph, IndexGraph};
use rs_graph::linkedlistgraph::*;
use rs_graph::classes;
#[derive(Graph)]
struct MyGraph {
#[graph] graph: LinkedListGraph, balances: Vec<f64>,
bounds: Vec<f64>,
}
impl From<LinkedListGraph> for MyGraph {
fn from(g: LinkedListGraph) -> MyGraph {
let n = g.num_nodes();
let m = g.num_edges();
MyGraph {
graph: g,
balances: vec![0.0; n],
bounds: vec![0.0; m],
}
}
}
impl MyGraph {
fn balance_mut(&mut self, u: Node) -> &mut f64 {
&mut self.balances[self.graph.node_id(u)]
}
fn bound_mut(&mut self, e: Edge) -> &mut f64 {
&mut self.bounds[self.graph.edge_id(e)]
}
}
# fn main() {
let mut g: MyGraph = classes::path::<LinkedListGraph>(5).into();
let (s, t) = (g.id2node(0), g.id2node(4));
*g.balance_mut(s) = 1.0;
*g.balance_mut(t) = -1.0;
for e in g.edges() { *g.bound_mut(e) = g.edge_id(e) as f64; }
# }