dtolnay / paste

Macros for all your token pasting needs
Apache License 2.0
981 stars 53 forks source link

Snake case preserving `/` (slash) characters #98

Open brownjohnf opened 10 months ago

brownjohnf commented 10 months ago

I'm attempting to use $expr:snake with a path containing slashes. My use-case is for automating tests, where test fixtures are in a hierarchical structure, and I'm auto-generating test modules based on the path I want to test:

mymacro!("some/file/path");

// I'd like this to expand to:
mod test_mymacro_some_file_path {..}

When using something like:

[< test_mymacro_ $expr:snake >]

it preserves the slash. I'm not sure what the expected/desired behavior is here; I see that the source explicitly only checks for case, not symbols, etc. Is there a way to achieve this with paste, or should I be doing something else, like using a $(path:ident)/+ pattern or something in my macro? I'm relatively new to writing macros, so apologies if I'm missing something obvious. This crate has been amazing for creating a robust test suite.

ThinkerDreamer commented 1 month ago

I have the same problem now: needing to convert a path string to a valid Rust identifier.