Figment
Figment copied to clipboard
Fail to deserialize `RelativePathBuf` in a enum
Hello, thank you for your work! Figment is really an awesome work with ergonomic designs.
But I encounter some problems when I would like to deserialize a struct with RelativePathBuf
as its field, which is inside an enum:
#[derive(Serialize, Deserialize, Debug)]
pub struct Test {
trace: RelativePathBuf,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "tp")]
pub enum Mode {
Test(Test),
}
I'm using the following code to extract the enum:
fn main() {
let m = figment::Figment::new().merge(Toml::file("./mode.toml")).extract::<Mode>().unwrap();
}
Inside the mode.toml
file is:
tp = "Test"
trace = "./123.json"
This will result in an error:
called `Result::unwrap()` on an `Err` value: Error { tag: Tag::Default, profile: None, metadata: None, path: [], kind: InvalidType(Str("./123.json"), "struct RelativePathBuf"), prev: None }
If I change the RelativePathBuf
to String
, then it works.
It also works if I directly deserialize the struct Test
with its field type still as RelativePathBuf
, e.g. with:
fn main(){
let t = figment::Figment::new().merge(Toml::file("./test.toml")).extract::<Test>().unwrap();
}
and in the test.toml
:
trace = "./123.json"
I'm wondering if there is a way to fix my problem, or is this behavior intended?
The deps I'm using:
[dependencies]
figment = { version = "0.10.19", features = ["toml", "json"] }
serde = { version = "1.0.203", features = ["derive"] }
toml = "0.8.14"