[−][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 theenum
variants by name into the same formats as supported by the serde attributerename_all
. This includes:lowercase
- makes variant names lowercaseUPPERCASE
- makes variant names UPPERCASEPascalCase
- makes variant names PascalCasecamelCase
- makes variant names camelCasesnake_case
- makes variant names snake_caseSCREAMING_SNAKE_CASE
- makes variant names SCREAMING_SNAKE_CASEkebab-case
- makes variant names kebab-caseSCREAMING-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 theenum
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
impl
s.
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.