Skip to main content

sim_lib_view_agent/
persist.rs

1//! Saving and loading a composed topology as SIM data.
2//!
3//! A topology saves and loads through the existing topology reflection -- there
4//! is no second package format. `composer_save` reflects a `Graph` to a value;
5//! `composer_load` parses a value back into a `Graph`.
6
7use sim_kernel::{Cx, Expr, Result};
8use sim_lib_topology::{Graph, graph_from_value, topology_reflect_graph};
9
10/// Reflect a `Graph` to a SIM value for saving, sharing, or diffing.
11pub fn composer_save(cx: &Cx, graph: &Graph) -> Expr {
12    topology_reflect_graph(cx, graph)
13}
14
15/// Parse a saved SIM value back into a `Graph`.
16pub fn composer_load(cx: &mut Cx, value: Expr) -> Result<Graph> {
17    let value = cx.factory().expr(value)?;
18    graph_from_value(cx, value)
19}