dtolnay / paste

Macros for all your token pasting needs
Apache License 2.0
1.02k stars 56 forks source link

[Feature Request] Inflection (aka plurals and sinulars) #96

Closed greyblake closed 1 year ago

greyblake commented 1 year ago

Hi, thank for the nice crate, it save me time and boilerplate today!

Motivaiton

This modifiers like $var:snake:upper are very helpful and prevents from some repetition. However, sometimes there are not sufficient, there some cases when a thing needs to be converted to it's plural (or maybe singular form).

For example: it would be cool to be able to derive from User model a table where it's stored (users).

Examples

Challenges

Due to the English grammar, just adding s is not always sufficient. For example:

So the problem is not very trivial. A good news, that Rails has it for almost 2 decades, and we can peek some ideas there. In Rails, the module responsible for this is called Inflector: https://api.rubyonrails.org/classes/ActiveSupport/Inflector.html

It seems to be that this problem also already solved in Rust. There are plenty of crates doing this: https://crates.io/search?q=singular%20plural inflection-rs seems to be the most decent among them.

I'd like to hear from you:

Thank you in advance!

dtolnay commented 1 year ago

I think I would prefer not to build this into this crate. But it would be a neat feature for someone else to maintain in a separate crate.