Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to deserialize RelativePathBuf in a enum #107

Open
BobAnkh opened this issue Jun 11, 2024 · 0 comments
Open

Fail to deserialize RelativePathBuf in a enum #107

BobAnkh opened this issue Jun 11, 2024 · 0 comments

Comments

@BobAnkh
Copy link

BobAnkh commented Jun 11, 2024

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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant