dtolnay / paste

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

Added test for lower casing corner case + fix #61

Open bogdanstate opened 3 years ago

bogdanstate commented 3 years ago

Thanks for the really nifty crate! I came across a small issue recently when writing a program that makes heavy use of meta-programming, including of the paste crate.

I have a string of the form ACMECorp. I use both paste to convert it to lower snake case when it's an identifier, as well as inflector when it's a value. paste converts the string as a_c_m_e_corp, whereas inflector converts it to acme_corp. To me, the latter solution feels like the more idiomatic way to do this case conversion.

I was able to reproduce this example by writing a test against the ACMECorp identifier. I got it to fail, and tried to change the original implementation to match the inflector behavior, but the logic turned out to be too complex. And indeed, in the inflector code, there is quite a bit more logic dealing with this sort of complexity. So I gave up and added a dependency on inflector.

I noticed that you have no other dependencies in this crate, so I don't know to what extent this is okay as far as the main branch is concerned, but this does solve my own problem for the time being. I figured I would share what I have so far, since this is a working solution for a small but surprisingly annoying problem.

bogdanstate commented 2 years ago

Just a quick note on this PR. I really need to use this behavior in a project I am about to publish on crates.io. Given the widespread use of paste in Rust, I understand why you might not want to add a dependency on Inflector. This is why I published a crate associated with my fork (which contains the proposed fix) as aorist_paste. I preserved the license in the crate, gave credit to @dtolnay as the main author and added my name as the crate maintainer. Hoping this is okay -- will yank the crate once I either find a more elegant way to deal with this issue myself or once it's fixed in the paste crate.