wolf-graph 0.1.0

Data structures and algorithms for working with graphs with reference or value semantics.
Documentation
use serde::Serialize;
use anyhow::{bail, Result};

// If `expected_json` is the empty string, the JSON representation of `value` will just
// be printed to the console.
pub fn recode<T: Serialize + PartialEq + std::fmt::Debug + serde::de::DeserializeOwned>(value: &T, expected_json: &str) -> Result<()> {
    let json = serde_json::to_string(&value).unwrap();
    if expected_json.is_empty() {
        println!("{}", json);
    } else if json != expected_json {
        bail!("serialized JSON does not match expected JSON\nexpected: {}\nactual: {}", expected_json, json);
    }
    let value2: T = serde_json::from_value(serde_json::to_value(value).unwrap()).unwrap();
    // assert!(&value2 == value, "deserialized value does not match original value");
    if &value2 != value {
        bail!("deserialized value does not match original value\noriginal: {:?}\ndeserialized: {:?}", value, value2);
    }
    Ok(())
}