Trait GraphBehaviour

Source
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§

Source

type Vertex

A type representing a vertex.

Source

type Edge

A type representing an edge.

Source

type VertexId

A type identifying a vertex.

Source

type EdgeId

A type identifying an edge.

Required Methods§

Source

fn vertices(&self) -> impl Iterator<Item = &Self::Vertex>

Returns an iterator over the vertices of the graph.

Source

fn edges(&self) -> impl Iterator<Item = &Self::Edge>

Returns an iterator over the edges of the graph, each represented as a tuple of vertices.

Source

fn add_vertex(&mut self, v: impl Into<Self::Vertex>)

Adds a vertex to the graph.

Source

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.

Source

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.

Source

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§

Source

fn add_vertices( &mut self, vertices: impl IntoIterator<Item = impl Into<Self::Vertex>>, )

Adds an iterable of vertices to the graph.

Source

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.

Source

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.

Source

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.

Source

fn vertex_count(&self) -> usize

Returns the number of vertices in the graph.

Source

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.

Implementors§