pub trait Graph {
type NodeId: Copy + Eq + Hash + Ord + Debug;
type EdgeId: Copy + Eq + Hash + Ord + Debug;
type Hasher: BuildHasher + Default;
type Node<'graph>: Node<'graph, Graph = Self>
where Self: 'graph;
type Edge<'graph>: Edge<'graph, Graph = Self>
where Self: 'graph;
// Required methods
fn get_node(&self, id: Self::NodeId) -> Option<Self::Node<'_>>;
fn get_edge(&self, id: Self::EdgeId) -> Option<Self::Edge<'_>>;
fn nodes(&self) -> impl Iterator<Item = Self::Node<'_>> + '_;
fn edges(&self) -> impl Iterator<Item = Self::Edge<'_>> + '_;
// Provided methods
fn dfs(&self, root: Self::NodeId) -> DfsIter<'_, Directed, Self> ⓘ
where Self: Sized { ... }
fn undirected_dfs(
&self,
root: Self::NodeId,
) -> DfsIter<'_, Undirected, Self> ⓘ
where Self: Sized { ... }
}Expand description
A typed graph container.
The graph is parameterized by:
NodeId: strongly typed node identifierEdgeId: strongly typed edge identifier
Required Associated Types§
type NodeId: Copy + Eq + Hash + Ord + Debug
type EdgeId: Copy + Eq + Hash + Ord + Debug
Sourcetype Hasher: BuildHasher + Default
type Hasher: BuildHasher + Default
Hasher backing the graph’s incident-edge sets and DFS bookkeeping.
The trait is generic over the hasher rather than pinning a concrete one:
picking a fixed-seed hasher (e.g. rustc_hash::FxBuildHasher) makes
predecessors()/successors() iteration order deterministic across
runs, whereas the std default (RandomState) reseeds per process.
type Node<'graph>: Node<'graph, Graph = Self> where Self: 'graph
type Edge<'graph>: Edge<'graph, Graph = Self> where Self: 'graph
Required Methods§
Sourcefn get_node(&self, id: Self::NodeId) -> Option<Self::Node<'_>>
fn get_node(&self, id: Self::NodeId) -> Option<Self::Node<'_>>
Gets a node in the graph by its identifier, if it exists.
fn get_edge(&self, id: Self::EdgeId) -> Option<Self::Edge<'_>>
Provided Methods§
Sourcefn dfs(&self, root: Self::NodeId) -> DfsIter<'_, Directed, Self> ⓘwhere
Self: Sized,
fn dfs(&self, root: Self::NodeId) -> DfsIter<'_, Directed, Self> ⓘwhere
Self: Sized,
A dfs iterator over the graph starting from the root, if present.
Sourcefn undirected_dfs(&self, root: Self::NodeId) -> DfsIter<'_, Undirected, Self> ⓘwhere
Self: Sized,
fn undirected_dfs(&self, root: Self::NodeId) -> DfsIter<'_, Undirected, Self> ⓘwhere
Self: Sized,
A dfs iterator over the graph treating edges as undirected.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".