wolf_graph/traits/
mutable_graph.rs

1use anyhow::Result;
2
3use crate::{EdgeID, NodeID, VisitableGraph};
4
5pub trait MutableGraph: VisitableGraph {
6    fn add_node_with_data(&mut self, id: impl AsRef<NodeID>, data: Self::NData) -> Result<()>;
7
8    fn adding_node_with_data(&self, id: impl AsRef<NodeID>, data: Self::NData) -> Result<Self>
9    where
10        Self: Clone + Sized
11    {
12        let mut graph = self.clone();
13        graph.add_node_with_data(id, data)?;
14        Ok(graph)
15    }
16
17    fn add_node(&mut self, id: impl AsRef<NodeID>) -> Result<()>
18    where
19        Self::NData: Default,
20    {
21        self.add_node_with_data(id, Self::NData::default())
22    }
23
24    fn adding_node(&self, id: impl AsRef<NodeID>) -> Result<Self>
25    where
26        Self: Clone + Sized,
27        Self::NData: Default,
28    {
29        let mut graph = self.clone();
30        graph.add_node(id)?;
31        Ok(graph)
32    }
33
34    fn add_edge_with_data(&mut self, id: impl AsRef<EdgeID>, source: impl AsRef<NodeID>, target: impl AsRef<NodeID>, data: Self::EData) -> Result<()>;
35
36    fn adding_edge_with_data(&self, id: impl AsRef<EdgeID>, source: impl AsRef<NodeID>, target: impl AsRef<NodeID>, data: Self::EData) -> Result<Self>
37    where
38        Self: Clone + Sized
39    {
40        let mut graph = self.clone();
41        graph.add_edge_with_data(id, source, target, data)?;
42        Ok(graph)
43    }
44
45    fn add_edge(&mut self, id: impl AsRef<EdgeID>, source: impl AsRef<NodeID>, target: impl AsRef<NodeID>) -> Result<()>
46    where
47        Self::EData: Default,
48    {
49        self.add_edge_with_data(id, source, target, Self::EData::default())
50    }
51
52    fn adding_edge(&self, id: impl AsRef<EdgeID>, source: impl AsRef<NodeID>, target: impl AsRef<NodeID>) -> Result<Self>
53    where
54        Self: Clone + Sized,
55        Self::EData: Default,
56    {
57        let mut graph = self.clone();
58        graph.add_edge(id, source, target)?;
59        Ok(graph)
60    }
61
62    fn remove_edge(&mut self, id: impl AsRef<EdgeID>) -> Result<()>;
63
64    fn removing_edge(&self, id: impl AsRef<EdgeID>) -> Result<Self>
65    where
66        Self: Clone + Sized
67    {
68        let mut graph = self.clone();
69        graph.remove_edge(id)?;
70        Ok(graph)
71    }
72
73    fn clear_edges(&mut self, id: impl AsRef<NodeID>) -> Result<()>;
74
75    fn clearing_edges(&self, id: impl AsRef<NodeID>) -> Result<Self>
76    where
77        Self: Clone + Sized
78    {
79        let mut graph = self.clone();
80        graph.clear_edges(id)?;
81        Ok(graph)
82    }
83
84    fn remove_node(&mut self, id: impl AsRef<NodeID>) -> Result<()>;
85
86    fn removing_node(&self, id: impl AsRef<NodeID>) -> Result<Self>
87    where
88        Self: Clone + Sized
89    {
90        let mut graph = self.clone();
91        graph.remove_node(id)?;
92        Ok(graph)
93    }
94
95    fn move_edge(&mut self, id: impl AsRef<EdgeID>, new_source: impl AsRef<NodeID>, new_target: impl AsRef<NodeID>) -> Result<()>;
96
97    fn moving_edge(&self, id: impl AsRef<EdgeID>, new_source: impl AsRef<NodeID>, new_target: impl AsRef<NodeID>) -> Result<Self>
98    where
99        Self: Clone + Sized
100    {
101        let mut graph = self.clone();
102        graph.move_edge(id, new_source, new_target)?;
103        Ok(graph)
104    }
105
106    fn set_data(&mut self, data: Self::GData);
107
108    fn setting_data(&self, data: Self::GData) -> Self
109    where
110        Self: Clone + Sized
111    {
112        let mut graph = self.clone();
113        graph.set_data(data);
114        graph
115    }
116
117    fn set_node_data(&mut self, id: impl AsRef<NodeID>, data: Self::NData) -> Result<()>;
118
119    fn setting_node_data(&self, id: impl AsRef<NodeID>, data: Self::NData) -> Result<Self>
120    where
121        Self: Clone + Sized
122    {
123        let mut graph = self.clone();
124        graph.set_node_data(id, data)?;
125        Ok(graph)
126    }
127
128    fn set_edge_data(&mut self, id: impl AsRef<EdgeID>, data: Self::EData) -> Result<()>;
129
130    fn setting_edge_data(&self, id: impl AsRef<EdgeID>, data: Self::EData) -> Result<Self>
131    where
132        Self: Clone + Sized
133    {
134        let mut graph = self.clone();
135        graph.set_edge_data(id, data)?;
136        Ok(graph)
137    }
138
139    fn with_data(&mut self, transform: &dyn Fn(&mut Self::GData));
140
141    fn with_node_data(&mut self, id: impl AsRef<NodeID>, transform: &dyn Fn(&mut Self::NData)) -> Result<()>;
142
143    fn with_edge_data(&mut self, id: impl AsRef<EdgeID>, transform: &dyn Fn(&mut Self::EData)) -> Result<()>;
144}