| Crates.io | derive_static_str |
| lib.rs | derive_static_str |
| version | 0.1.1 |
| created_at | 2024-12-23 19:49:25.544713+00 |
| updated_at | 2024-12-24 00:05:28.60119+00 |
| description | A procedural macro to derive static str implementations |
| homepage | |
| repository | https://github.com/iamnbutler/derive_static_str |
| max_upload_size | |
| id | 1493367 |
| size | 12,216 |
A proc macro for composing static string slices from enum variants. Sometimes you just want a &'static str with some prefix or suffix...
Add derive_static_str and strum to your Cargo.toml:
[dependencies]
derive_static_str = "0.1.0"
strum = { version = "0.24", features = ["derive"] }
Both prefixes and suffixes can be added via:
#[static_str(prefix = "...")]
#[static_str(suffix = "...")]
The overall case of the output can be controlled with strum's serialize_all.
use derive_static_str::{static_str, DeriveStaticStr};
use strum::EnumString;
#[derive(EnumString, DeriveStaticStr)]
#[static_str(prefix = "my_prefix_", suffix = "_suffix")]
#[strum(serialize_all = "snake_case")]
enum MyEnum {
VariantOne,
VariantTwo,
}
fn main() {
assert_eq!(MyEnum::VariantOne.as_static_str(), "my_prefix_variant_one_suffix");
assert_eq!(MyEnum::VariantTwo.as_static_str(), "my_prefix_variant_two_suffix");
}