Peternator7 / strum

A small rust library for adding custom derives to enums
https://crates.io/crates/strum
MIT License
1.8k stars 152 forks source link

Fix camel_case to PascalCase bug #250

Closed bouzuya closed 1 year ago

bouzuya commented 1 year ago

Specifying camel_case for serialize_all will result in a PascalCase. Is this the intended behavior?

This pull request assumes that this is unintended behavior and fixes it.


This is not related to this pull request, but I have a point of concern. If you allow a snake_case specification for each variant, I would like to see it supported for all variants. Otherwise, I think it would be a good idea to reject the camel_case and kebab_case specifications.

https://github.com/Peternator7/strum/pull/250/files#diff-801759161311a5149bd0d6c227fea4237bb6d8a8bb9e84f4703d305e2f131ae1R129

The serde crate rename_all attribute appears to reject it.

https://github.com/serde-rs/serde/blob/ce0844b9ecc32377b5e4545d759d385a8c46bc6a/serde_derive/src/internals/case.rs#L38-L59

Peternator7 commented 1 year ago

Hi @bouzuya, I think this is an awkward case where it's by design. Heck (which provides the casing) refers to the cases as lowerCamelCase and UpperCamelCase so the original names for the case styles followed it's convention. As you noticed, the newer case-styles follow the pattern serde does of using the style itself in the name and that follows the more generally used convention of camelCase and PascalCase.

The docs recommend using the new naming format so I consider the old names to be soft-deprecated, but I don't think it's worth causing a breaking change by removing the old names or what they do.

bouzuya commented 1 year ago

Thank you for your answer. I understood as follows.

Based on your answer, I am going to stop changing the behavior (removing camel_case) and leave a comment stating that it is soft-deprecated.