Hi, I am new to Rust and just curious if it is possible to do such a thing with thiserror and serde, or any other crate without implementing a serializer or deserializer.
#[derive(Error, Serialize, Deserialize)]
enum Errors {
#[error("the power is out")]
PowerOut,
#[error("{0}")]
Missing(String),
}
let err1 = serde_json::to_string(&Errors::PowerOut)
println!("{}", err1);
//will print {"PowerOut" : "the power is out"}
let err2 = serde_json::to_string(&Errors::Missing("test"))
println!("{}", err1);
//will print {"Missing" : "test"}
println!("{:?}", serde_json::from_str::<Errors>(&err1));
//will print Ok(Errors::PowerOut)
println!("{:?}", serde_json::from_str::<Errors>(&err2));
//will print Ok(Errors::Missing)
Thanks in advance