//! This example shows how to serialize and deserialize `jstrict::Value`
//! using the `serde` crate. This will not allow you to attach metadata to each
//! value fragment (the `M` type will be unit `()`).
usejstrict::Print;usestd::error::Error;#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize)]structMyType{foo: String,
bar:Vec<u32>,
}fnmain()->Result<(), Box<dyn Error>>{// Instantiate our type.
let a = MyType {
foo:"Hello World!".to_string(),
bar:vec![1,2,3],};// Serialize `a` into a JSON value.
let json =jstrict::to_value(&a)?;// Print the value.
println!("{}", json.pretty_print());// Deserialize JSON back into `MyType`.
let b: MyType =jstrict::from_value(json)?;// The round-trip should not change the actual data.
assert_eq!(a, b);Ok(())}