[][src]Attribute Macro serde_json_helpers::serde_enum_string

#[serde_enum_string]

Allows a C-style enum to be serialized as a string, useful for human-readable JSON.

Takes two optional attributes:

  • transform = "<type>" - transform the enum variants by name into the same formats as supported by the serde attribute rename_all. This includes:

    • lowercase - makes variant names lowercase
    • UPPERCASE - makes variant names UPPERCASE
    • PascalCase - makes variant names PascalCase
    • camelCase - makes variant names camelCase
    • snake_case - makes variant names snake_case
    • SCREAMING_SNAKE_CASE - makes variant names SCREAMING_SNAKE_CASE
    • kebab-case - makes variant names kebab-case
    • SCREAMING-KEBAB-CASE - makes variant names SCREAMING-KEBAB-CASE

    If unspecified, the enum variant names will be passed through unmodified.

  • prepend_enum_name - Add the name of the enum to the values for each variant. This will be prepended to the variant name before running the transform described above.

Note that this macro is incompatible with existing Serialize and Deserialize impls. If a Serialize or Deserialize derive is detected, this macro will panic, but if you impl them directly you will just get normal compiler issues which you're on your own to figure out.