daedalus_planner/
debug.rs

1//! Debug helpers for serializing/deserializing plans, useful for goldens/CLI.
2//! ```
3//! use daedalus_planner::{debug, Graph, ExecutionPlan};
4//!
5//! let plan = ExecutionPlan::new(Graph::default(), vec![]);
6//! let json = debug::to_pretty_json(&plan);
7//! let round = debug::from_json(&json).unwrap();
8//! assert_eq!(plan.version, round.version);
9//! ```
10use crate::ExecutionPlan;
11
12/// Serialize a plan to pretty-printed JSON.
13pub fn to_pretty_json(plan: &ExecutionPlan) -> String {
14    serde_json::to_string_pretty(plan).expect("serialize plan")
15}
16
17/// Serialize a plan to compact JSON.
18pub fn to_json(plan: &ExecutionPlan) -> String {
19    serde_json::to_string(plan).expect("serialize plan")
20}
21
22/// Deserialize a plan from JSON.
23pub fn from_json(s: &str) -> Result<ExecutionPlan, serde_json::Error> {
24    serde_json::from_str(s)
25}