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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions _src/container-attrs.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
Use the untagged enum representation for this enum. See [enum
representations](enum-representations.md) for details on this representation.

- ##### `#[serde(variant_identifier)]` {#variant--identifier}

Use an identifier representation for this enum. This can only be applied to enums that are C-like (containing only unit variants), and forces them to always be represented as strings, regardless of the underlying data format's representation of enums.

- ##### `#[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.
Comment on lines +59 to +61
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.


- ##### `#[serde(bound = "T: MyTrait")]` {#bound}

Where-clause for the `Serialize` and `Deserialize` impls. This replaces any
Expand Down