| Crates.io | ident-str |
| lib.rs | ident-str |
| version | 0.1.0 |
| created_at | 2025-11-13 02:57:47.148439+00 |
| updated_at | 2025-11-13 02:57:47.148439+00 |
| description | A macro to convert string literals into identifiers |
| homepage | |
| repository | https://github.com/funnyboy-roks/ident-str |
| max_upload_size | |
| id | 1930328 |
| size | 35,111 |
A macro to convert string literals into identifiers. The primary use-case is to allow declarative macros to produce identifiers that are unique to each call. The alternative is to accept each identifier as an argument to the macro call, which gets unweildy with many identifiers.
macro_rules! my_macro {
($name: ident) => {
ident_str::ident_str! {
#name_a = concat!(stringify!($name), "_a"),
#name_b = concat!(stringify!($name), "_b")
=> {
fn #name_a() {}
fn #name_b() {}
}
}
};
}
my_macro!(foo);
expands to
fn foo_a() {}
fn foo_b() {}
This crate takes advantage of MacroString and
supports all macros supported by it. Those macros are:
concat!stringify!env!include!include_str!When any unknown variables are encountered, ident_str! will error, if that behaviour is not
desired, you can add #<var> = None to the declarations:
ident_str::ident_str! {
#ignore = None
=> #ignore
}
This exapands into
#ignore