Using the config
crate, when freezing the configuration, viz
let cfg = config.try_into::<MyConfig>();
where MyConfig
is nested structure that includes Process
,
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Process {
Server { name: String },
Coord { name: String, parent: String, filename: String },
Model { name: String, parent: String, filename: String },
None,
}
However, when I pass
config.set("command.process", serde_json::to_string(&p).unwrap())?;
and start to freeze config into MyConfig
, I obtain the following error:
enum Process does not have variant constructor {"Coord":{"name":"MyCoord1","parent":"ParentCoord","filename":"/tmp/coord.py"}}
Yet I can do the following:
let p = Process::Coord {
name: "MyCoord1".to_string(),
parent: "ParentCoord".to_string(),
filename: "/tmp/coord.py".to_string()
};
let ps = serde_json::to_string(&p).unwrap();
let pd: Process = serde_json::from_str(&ps).unwrap();
println!("{:#?}\n{:#?}", ps, pd);
I've tried various potential 'solutions' (implementing Deserialize, Visitor, FromStr) without recourse... Help much appreciated!
BTW:
Even when taking the variant constructor out of the enum, i.e.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Coord {
name: String,
parent: String,
filename: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Process {
Server { name: String },
// Coord { name: String, parent: String, filename: String },
Coord ( Coord ),
Model { name: String, parent: String, filename: String },
None,
I obtain the same error:
Error: enum Process does not have variant constructor {"Coord":{"name":"MyCoord1","parent":"ParentCoord","filename":"/tmp/coord.py"}}