Peternator7 / strum

A small rust library for adding custom derives to enums
https://crates.io/crates/strum
MIT License
1.8k stars 151 forks source link

Add the `prefix` attribute #296

Closed chanman3388 closed 11 months ago

chanman3388 commented 1 year ago

The idea here was to allow the addition of the prefix attribute such that when displaying the enum variant that said variant will have the prefix. This should be exempt from other formatting. Example usage:

use strum::{Display, EnumString};

#[derive(Debug, EnumString, Display)]
#[strum(prefix = "prefix")]
enum Thing {
    Test,
}

fn main() {
    println!("{}", Thing::Test);  // prints "prefixTest"
}

Could possibly add some kind of skipping mechanism for individual variants.

Peternator7 commented 11 months ago

Looks great! Merged