wolf-graph 0.1.0

Data structures and algorithms for working with graphs with reference or value semantics.
Documentation
use anyhow::Result;

use crate::{EdgeID, NodeID, VisitableGraph};

pub trait MutableGraph: VisitableGraph {
    fn add_node_with_data(&mut self, id: impl AsRef<NodeID>, data: Self::NData) -> Result<()>;

    fn adding_node_with_data(&self, id: impl AsRef<NodeID>, data: Self::NData) -> Result<Self>
    where
        Self: Clone + Sized
    {
        let mut graph = self.clone();
        graph.add_node_with_data(id, data)?;
        Ok(graph)
    }

    fn add_node(&mut self, id: impl AsRef<NodeID>) -> Result<()>
    where
        Self::NData: Default,
    {
        self.add_node_with_data(id, Self::NData::default())
    }

    fn adding_node(&self, id: impl AsRef<NodeID>) -> Result<Self>
    where
        Self: Clone + Sized,
        Self::NData: Default,
    {
        let mut graph = self.clone();
        graph.add_node(id)?;
        Ok(graph)
    }

    fn add_edge_with_data(&mut self, id: impl AsRef<EdgeID>, source: impl AsRef<NodeID>, target: impl AsRef<NodeID>, data: Self::EData) -> Result<()>;

    fn adding_edge_with_data(&self, id: impl AsRef<EdgeID>, source: impl AsRef<NodeID>, target: impl AsRef<NodeID>, data: Self::EData) -> Result<Self>
    where
        Self: Clone + Sized
    {
        let mut graph = self.clone();
        graph.add_edge_with_data(id, source, target, data)?;
        Ok(graph)
    }

    fn add_edge(&mut self, id: impl AsRef<EdgeID>, source: impl AsRef<NodeID>, target: impl AsRef<NodeID>) -> Result<()>
    where
        Self::EData: Default,
    {
        self.add_edge_with_data(id, source, target, Self::EData::default())
    }

    fn adding_edge(&self, id: impl AsRef<EdgeID>, source: impl AsRef<NodeID>, target: impl AsRef<NodeID>) -> Result<Self>
    where
        Self: Clone + Sized,
        Self::EData: Default,
    {
        let mut graph = self.clone();
        graph.add_edge(id, source, target)?;
        Ok(graph)
    }

    fn remove_edge(&mut self, id: impl AsRef<EdgeID>) -> Result<()>;

    fn removing_edge(&self, id: impl AsRef<EdgeID>) -> Result<Self>
    where
        Self: Clone + Sized
    {
        let mut graph = self.clone();
        graph.remove_edge(id)?;
        Ok(graph)
    }

    fn clear_edges(&mut self, id: impl AsRef<NodeID>) -> Result<()>;

    fn clearing_edges(&self, id: impl AsRef<NodeID>) -> Result<Self>
    where
        Self: Clone + Sized
    {
        let mut graph = self.clone();
        graph.clear_edges(id)?;
        Ok(graph)
    }

    fn remove_node(&mut self, id: impl AsRef<NodeID>) -> Result<()>;

    fn removing_node(&self, id: impl AsRef<NodeID>) -> Result<Self>
    where
        Self: Clone + Sized
    {
        let mut graph = self.clone();
        graph.remove_node(id)?;
        Ok(graph)
    }

    fn move_edge(&mut self, id: impl AsRef<EdgeID>, new_source: impl AsRef<NodeID>, new_target: impl AsRef<NodeID>) -> Result<()>;

    fn moving_edge(&self, id: impl AsRef<EdgeID>, new_source: impl AsRef<NodeID>, new_target: impl AsRef<NodeID>) -> Result<Self>
    where
        Self: Clone + Sized
    {
        let mut graph = self.clone();
        graph.move_edge(id, new_source, new_target)?;
        Ok(graph)
    }

    fn set_data(&mut self, data: Self::GData);

    fn setting_data(&self, data: Self::GData) -> Self
    where
        Self: Clone + Sized
    {
        let mut graph = self.clone();
        graph.set_data(data);
        graph
    }

    fn set_node_data(&mut self, id: impl AsRef<NodeID>, data: Self::NData) -> Result<()>;

    fn setting_node_data(&self, id: impl AsRef<NodeID>, data: Self::NData) -> Result<Self>
    where
        Self: Clone + Sized
    {
        let mut graph = self.clone();
        graph.set_node_data(id, data)?;
        Ok(graph)
    }

    fn set_edge_data(&mut self, id: impl AsRef<EdgeID>, data: Self::EData) -> Result<()>;

    fn setting_edge_data(&self, id: impl AsRef<EdgeID>, data: Self::EData) -> Result<Self>
    where
        Self: Clone + Sized
    {
        let mut graph = self.clone();
        graph.set_edge_data(id, data)?;
        Ok(graph)
    }

    fn with_data(&mut self, transform: &dyn Fn(&mut Self::GData));

    fn with_node_data(&mut self, id: impl AsRef<NodeID>, transform: &dyn Fn(&mut Self::NData)) -> Result<()>;

    fn with_edge_data(&mut self, id: impl AsRef<EdgeID>, transform: &dyn Fn(&mut Self::EData)) -> Result<()>;
}