-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add kebab-case macro #12
Comments
hi @TYTheBeast , thanks for the issue. could you explain your usecase a little more? |
Hiya jordy, my use case is in a macro in a project I've been working on, specifically this file, where I'd need the generated to string format to be kebab-case in order to keep the command line arguments for the search_item binary consistent, as the sort by arguments are kebab-case but the min/max arguments are lowercase. My main use case is together with stringify in the macro. The issue is that in https://github.com/TYTheBeast/WynnBuilderTools-Rekindled/blob/master/src/args/item_search_args.rs in the parse_key_val_sort_by function, I have to parse from a format, currently lowercase, to my custom generated enum. |
maybe better to convert the input string into camelcase, rather than the enum variant into kebab-case e.g: diff --git a/src/args/generate_sort_by.rs b/src/args/generate_sort_by.rs
index 962c049..109bfbf 100644
--- a/src/args/generate_sort_by.rs
+++ b/src/args/generate_sort_by.rs
@@ -10,8 +10,9 @@ macro_rules! generate_sort_by {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
- match s.to_lowercase().as_str() {
- $(lower!(stringify!($variant)) => Ok(SortAndFilterBy::$variant),)*
+ use heck::ToUpperCamelCase;
+ match s.to_upper_camel_case().as_str() {
+ $(stringify!($variant) => Ok(SortAndFilterBy::$variant),)*
_ => Err(format!("Unknown sort criterion: {}", s)),
}
} marking this as won't fix since kebab-case would create invalid rust syntax |
Would be really helpful if there was also a kebab-case macro, as I need it for my project in order to maintain consistency for command line arguments' format.
casey does not currently implement a kebab-case macro.
The text was updated successfully, but these errors were encountered: