Skip to main content

openinfer_simulator/graph/
serde.rs

1use anyhow::Result;
2use serde_json::Value;
3
4use crate::graph::Graph;
5
6/// Serialize graphs into JSON representations.
7pub struct GraphSerialize;
8
9impl GraphSerialize {
10    /// Convert a graph to a JSON value.
11    pub fn json(graph: &Graph) -> Result<Value> {
12        Ok(serde_json::to_value(graph)?)
13    }
14}
15
16/// Deserialize graphs from JSON representations.
17pub struct GraphDeserialize;
18
19impl GraphDeserialize {
20    /// Parse a graph from a JSON value.
21    pub fn from_json(value: Value) -> Result<Graph> {
22        Ok(serde_json::from_value(value)?)
23    }
24}