ruka_mir/browser_graph/
store.rs

1use super::*;
2
3impl<'a> BrowserMirGraphBuilder<'a> {
4    /// Insert one graph node and return its id.
5    pub(super) fn node(
6        &mut self,
7        id: String,
8        kind: &str,
9        summary: Option<String>,
10        category: &'static str,
11        details: Vec<String>,
12    ) -> String {
13        self.nodes.push(BrowserMirNode {
14            id: id.clone(),
15            kind: kind.to_owned(),
16            summary,
17            category,
18            construct_id: None,
19            details,
20        });
21        id
22    }
23
24    /// Append one detail line to an existing graph node.
25    pub(super) fn append_detail(&mut self, node_id: &str, detail: String) {
26        if let Some(node) = self.nodes.iter_mut().find(|node| node.id == node_id) {
27            node.details.push(detail);
28        }
29    }
30
31    /// Insert one synthetic graph node with a generated id.
32    pub(super) fn synthetic_node(
33        &mut self,
34        prefix: &str,
35        kind: &str,
36        summary: Option<String>,
37        category: &'static str,
38        details: Vec<String>,
39    ) -> String {
40        let id = format!("{prefix}-{}", self.next_synthetic_id);
41        self.next_synthetic_id += 1;
42        self.node(id, kind, summary, category, details)
43    }
44
45    /// Insert one directed graph edge.
46    pub(super) fn edge(
47        &mut self,
48        source: &str,
49        target: &str,
50        label: Option<&str>,
51        category: &'static str,
52    ) {
53        let id = format!("edge-{}", self.next_edge_id);
54        self.next_edge_id += 1;
55        self.edges.push(BrowserMirEdge {
56            id,
57            source: source.to_owned(),
58            target: target.to_owned(),
59            label: label.map(str::to_owned),
60            category,
61        });
62    }
63}