enum-stringify
A procedural macro crate to generate string representations of Rust enums.
Derive EnumStringify
to automatically implement Display
, TryFrom<&str>
, TryFrom<String>
, and FromStr
for your enum, using the variant name as the string representation.
Features
- Automatic string conversion: Implements
Display
,FromStr
, andTryFrom
for enums. - Customizable output: Add prefixes, suffixes, and change the case of the string representation.
- Ergonomic usage: Simple derive macro with useful defaults.
Usage
use EnumStringify;
use TryFrom;
use FromStr;
Custom String Representation
You can customize the string representation using attributes for prefix, suffix, and case.
use EnumStringify;
In this example, the string representation of MyEnum::Variant1
will be MyPrefixVARIANT1MySuffix
.
Supported options
- prefix: String prepended to each variant
- suffix: String appended to each variant
- case: Changes the case (
"upper_flat"
,"lower_flat"
, etc.)
Documentation
License
This project is licensed under the MIT License. See LICENSE for details.