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

#[derive(YaDeserialize)] requires Default #144

Open
Wassasin opened this issue May 25, 2022 · 3 comments
Open

#[derive(YaDeserialize)] requires Default #144

Wassasin opened this issue May 25, 2022 · 3 comments
Labels
enhancement New feature or request wait feedback The issue is addressed, wait a reply from the author

Comments

@Wassasin
Copy link

When deriving YaDeserialize the macro requires that all member types implement the Default trait. I suppose this is to instantiate a value even when the XML document is missing that child or attribute.

As a consumer of this crate I would have to either make all fields Option, or implement Default for all of them. However I would rather that YaDeserialize would throw an error if that child or attribute is missing from the XML, and have an attribute #[yaserde(default)] for the current behaviour.

MarcAntoine-Arnaud added a commit that referenced this issue Feb 5, 2024
@MarcAntoine-Arnaud MarcAntoine-Arnaud added enhancement New feature or request wait feedback The issue is addressed, wait a reply from the author labels Feb 6, 2024
@2xsaiko
Copy link

2xsaiko commented Feb 21, 2024

With 82df2e1, how do you specify the equivalent of #[serde(default)] (i.e. use Default::default if value missing)? There is a #[yaserde(default)] but it seems to be for something different since it takes a string value.

@Wassasin
Copy link
Author

It has been a long time since I created the relevant commit, but I believe the string can be used to specify a function name. This function will be called when the value is not provided in the XML input.

@2xsaiko
Copy link

2xsaiko commented Feb 21, 2024

Hmm, so it does indeed. It has to be in the current scope though, I tested with setting it to Default::default() (with or without the parens) before and it gave an invalid identifier error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wait feedback The issue is addressed, wait a reply from the author
Projects
None yet
Development

No branches or pull requests

3 participants