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

Add documentation for variant_identifier and field_identifier #146

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Lucretiel
Copy link

This PR adds documentation for the variant_identifier and field_identifier attributes on enums. I think this should be alright to make officially part of the public API, since they're mentioned in existing documentation, but I'm happy to be wrong about this.

Fixes serde-rs/serde#1238

Comment on lines +59 to +61
- ##### `#[serde(field_identifier)]` {#field--identifier}

Identical to [`variant_identifier`](#variant--identifier), but also allows for the last variant to be a newtype variant, which will be used if none of the other variants match (similar to [`#[serde(other)]`](../variant-attrs.html#other)). Like `variant_identifier`, this forces the enum to always be represented as a string, regardless of the underlying data format's representation of enums.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have an example here?

It doesn't seem to work based on the description:

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", field_identifier)]
pub enum Type {
    NixosModule,
    Derivation,
    App,
    Unknown(String),
}
image

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so when using this condition, Serialize cannot be derive automatically. That should be mentioned, although I wonder why this limitation even exists.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's a good catch. Probably it was only intended to support the intermediary enum types used during deserialization, so there was never a need to add serialize support. That's something I can look into adding in parallel with this docs PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

container attributes 'field_identifier' and 'variant_identifier' are not documented
2 participants