Skip to content
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

screaming kebab case doesn't treat numbers as separate word? #72

Closed
Luro02 opened this issue Sep 27, 2019 · 2 comments
Closed

screaming kebab case doesn't treat numbers as separate word? #72

Luro02 opened this issue Sep 27, 2019 · 2 comments

Comments

@Luro02
Copy link

Luro02 commented Sep 27, 2019

The following code doesn't work as expected

#[derive(Display)]
#[strum(serialize_all = "SCREAMING-KEBAB-CASE")]
enum Example {
    Aes128
}

assert_eq!(Example::Aes128, "AES-128".to_string());

instead strum generates:
"AES128"

@Peternator7
Copy link
Owner

Thanks for reaching out!

Strum delegates generating all of it's different cases to the heck crate. While I agree that's unexpected, I'm hesitant to add special cases on top of that library. I might suggest reaching out on that repo and see if they'd take a fix in their crate.

Thanks!

@jplatte
Copy link
Contributor

jplatte commented Jun 16, 2020

Might I suggest moving away from heck? It uses unicode word boundaries, which seems excessive for source code (I haven't seen anybody complain about serde's rename_all lacking support for #[feature(non_ascii_idents)] and I doubt anybody currently using strum needs that).

EDIT: I'm now maintaining the heck crate and will soon release a new version with the unicode-segmentation dependency being optional (but am still unsure whether it makes sense for strum to depend on it).

Maybe you could reuse serde's implementation or coordinate a shared crate for this logic with them?

That implementation does however also not put -s or _s between letters and digits. I would strongly suggest not deviating from serde's rename_all, no matter if you're using heck or not.

ssd532 added a commit to ssd532/heck that referenced this issue Jan 3, 2021
ConvertCase implements convert_case() which accepts customization options to tweak behaviour of other case conversion functions. Currently, it accepts `number_starts_word` option to have word boundaries when characters in a word change from numeric to alphabetic or vice versa. 

Other case conversion functions are implemented in terms on convert_case() by passing `number_starts_word` as false by default. 

ref: withoutboats#18
ref: Peternator7/strum#72
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants