Serde for thiserror without implementing serializer or deserializer in enum

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")]

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

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.