pub trait GraphBehaviour {
type Vertex;
type Edge;
type VertexId;
type EdgeId;
// Required methods
fn vertices(&self) -> impl Iterator<Item = &Self::Vertex>;
fn edges(&self) -> impl Iterator<Item = &Self::Edge>;
fn add_vertex(&mut self, v: impl Into<Self::Vertex>);
fn add_edge(&mut self, e: impl Into<Self::Edge>) -> Result<(), GraphError>;
fn remove_vertex_by_id(
&mut self,
v: impl Into<Self::VertexId>,
) -> Result<(), GraphError>;
fn remove_edge_by_id(
&mut self,
e: impl Into<Self::EdgeId>,
) -> Result<(), GraphError>;
// Provided methods
fn add_vertices(
&mut self,
vertices: impl IntoIterator<Item = impl Into<Self::Vertex>>,
) { ... }
fn add_edges(
&mut self,
edges: impl IntoIterator<Item = impl Into<Self::Edge>>,
) -> Result<(), GraphError> { ... }
fn remove_vertices_by_id(
&mut self,
vertices: impl IntoIterator<Item = impl Into<Self::VertexId>>,
) -> Result<(), GraphError> { ... }
fn remove_edges_by_id(
&mut self,
edges: impl IntoIterator<Item = impl Into<Self::EdgeId>>,
) -> Result<(), GraphError> { ... }
fn vertex_count(&self) -> usize { ... }
fn edge_count(&self) -> usize { ... }
}
Expand description
A trait defining basic graph behaviour.
Required Associated Types§
Required Methods§
Sourcefn vertices(&self) -> impl Iterator<Item = &Self::Vertex>
fn vertices(&self) -> impl Iterator<Item = &Self::Vertex>
Returns an iterator over the vertices of the graph.
Sourcefn edges(&self) -> impl Iterator<Item = &Self::Edge>
fn edges(&self) -> impl Iterator<Item = &Self::Edge>
Returns an iterator over the edges of the graph, each represented as a tuple of vertices.
Sourcefn add_vertex(&mut self, v: impl Into<Self::Vertex>)
fn add_vertex(&mut self, v: impl Into<Self::Vertex>)
Adds a vertex to the graph.
Sourcefn add_edge(&mut self, e: impl Into<Self::Edge>) -> Result<(), GraphError>
fn add_edge(&mut self, e: impl Into<Self::Edge>) -> Result<(), GraphError>
Adds an edge to the graph.
§Errors
Will return a GraphError
error if it is trying to connect vertices that do not
exist in the graph.
Sourcefn remove_vertex_by_id(
&mut self,
v: impl Into<Self::VertexId>,
) -> Result<(), GraphError>
fn remove_vertex_by_id( &mut self, v: impl Into<Self::VertexId>, ) -> Result<(), GraphError>
Attemps to remove a vertex from the graph.
§Errors
This function will return a GraphError
error if it cannot find the vertex to
remove.
Sourcefn remove_edge_by_id(
&mut self,
e: impl Into<Self::EdgeId>,
) -> Result<(), GraphError>
fn remove_edge_by_id( &mut self, e: impl Into<Self::EdgeId>, ) -> Result<(), GraphError>
Remove an edge from the graph.
§Errors
This function will return a GraphError
error if it cannot find the edge to remove.
Provided Methods§
Sourcefn add_vertices(
&mut self,
vertices: impl IntoIterator<Item = impl Into<Self::Vertex>>,
)
fn add_vertices( &mut self, vertices: impl IntoIterator<Item = impl Into<Self::Vertex>>, )
Adds an iterable of vertices to the graph.
Sourcefn add_edges(
&mut self,
edges: impl IntoIterator<Item = impl Into<Self::Edge>>,
) -> Result<(), GraphError>
fn add_edges( &mut self, edges: impl IntoIterator<Item = impl Into<Self::Edge>>, ) -> Result<(), GraphError>
Add an iterable of edges to the graph.
§Errors
Will return a GraphError
if it is trying to connect vertices that do not exist in
the graph.
Sourcefn remove_vertices_by_id(
&mut self,
vertices: impl IntoIterator<Item = impl Into<Self::VertexId>>,
) -> Result<(), GraphError>
fn remove_vertices_by_id( &mut self, vertices: impl IntoIterator<Item = impl Into<Self::VertexId>>, ) -> Result<(), GraphError>
Remove an iterable of vertices from the graph.
§Errors
This function will return a GraphError
error if it cannot find one of the vertices
to remove.
Sourcefn remove_edges_by_id(
&mut self,
edges: impl IntoIterator<Item = impl Into<Self::EdgeId>>,
) -> Result<(), GraphError>
fn remove_edges_by_id( &mut self, edges: impl IntoIterator<Item = impl Into<Self::EdgeId>>, ) -> Result<(), GraphError>
Remove an iterable of edges from the graph.
§Errors
This function will return a GraphError
error if it cannot find one of
the edges to remove.
Sourcefn vertex_count(&self) -> usize
fn vertex_count(&self) -> usize
Returns the number of vertices in the graph.
Sourcefn edge_count(&self) -> usize
fn edge_count(&self) -> usize
Returns the number of edges in the graph.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.