dot2/graph_walk.rs
1/// GraphWalk is an abstraction over a directed graph = (nodes,edges)
2/// made up of node handles `N` and edge handles `E`, where each `E`
3/// can be mapped to its source and target nodes.
4///
5/// The lifetime parameter `'a` is exposed in this trait (rather than
6/// introduced as a generic parameter on each method declaration) so
7/// that a client impl can choose `N` and `E` that have substructure
8/// that is bound by the self lifetime `'a`.
9///
10/// The `nodes` and `edges` method each return instantiations of
11/// `Cow<[T]>` to leave implementors the freedom to create
12/// entirely new vectors or to pass back slices into internally owned
13/// vectors.
14pub trait GraphWalk<'a> {
15 type Node: Clone;
16 type Edge: Clone;
17 type Subgraph: Clone;
18
19 /// Returns all the nodes in this graph.
20 fn nodes(&'a self) -> crate::Nodes<'a, Self::Node>;
21 /// Returns all of the edges in this graph.
22 fn edges(&'a self) -> crate::Edges<'a, Self::Edge>;
23 /// The source node for `edge`.
24 fn source(&'a self, edge: &Self::Edge) -> Self::Node;
25 /// The target node for `edge`.
26 fn target(&'a self, edge: &Self::Edge) -> Self::Node;
27
28 /// Retuns all the subgraphs in this graph.
29 fn subgraphs(&'a self) -> crate::Subgraphs<'a, Self::Subgraph> {
30 std::borrow::Cow::Borrowed(&[])
31 }
32
33 /// Retuns all the subgraphs in this graph.
34 fn subgraph_nodes(&'a self, _s: &Self::Subgraph) -> crate::Nodes<'a, Self::Node> {
35 std::borrow::Cow::Borrowed(&[])
36 }
37}