ident-str

Crates.ioident-str
lib.rsident-str
version0.1.0
created_at2025-11-13 02:57:47.148439+00
updated_at2025-11-13 02:57:47.148439+00
descriptionA macro to convert string literals into identifiers
homepage
repositoryhttps://github.com/funnyboy-roks/ident-str
max_upload_size
id1930328
size35,111
Funny (funnyboy-roks)

documentation

README

ident-str

Crates.io Documentation Dependency status

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.

Usage

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() {}

Supported Macros

This crate takes advantage of MacroString and supports all macros supported by it. Those macros are:

  • concat!
  • stringify!
  • env!
  • include!
  • include_str!

Ignore Variable

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
Commit count: 0

cargo fmt