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

Add compactlowercase and COMPACTUPPERCASE casing rules #50

Closed
wants to merge 3 commits into from

Conversation

coriolinus
Copy link

These rules transform the input case and eliminate spacing. Motivating example: (from serde-rs/serde#2153 (comment)):

I'm consuming an API which has objects with fields firstname, lastname, streetnumber, and the like. In a perfect world, I could write this as

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all="lowercase")]
struct FromForeignApi {
    first_name: String,
    last_name: String,
    street_number: String,
    // etc
}

However, attempting this, I encounter the surprising situation that unlike most rename_all rules, lowercase does not adjust the spacing between the words.

@jplatte
Copy link
Collaborator

jplatte commented Sep 15, 2023

Sorry, but I'm not going to accept this PR with yet another extremely uncommon casing rule. There's a chance custom casing rules will be supported in the future, see #6.

@jplatte jplatte closed this Sep 15, 2023
@coriolinus
Copy link
Author

This is more uncommon than train case? Looking at #38, the motivation seems to be as simple as "convert_case does it". convert_case handles these also.

@jplatte
Copy link
Collaborator

jplatte commented Oct 25, 2023

Squashing multi-word identifiers / titles / taglines into one all-lowercase or all-uppercase word is very uncommon I would say. Also (which is probably the distinguishing factor against Train-Case) there is no established name for this casing rule.

@coriolinus
Copy link
Author

I probably would have agreed that it's uncommon, until I ran into the problem of having to manually annotate dozens of #[serde(rename="whatever")] attributes in order to support that external API. At that point, it went from "whatever, it's uncommon" to "this is very important for me right now."

It is frustrating that this has been rejected based on a gut instinct about how common this is, plus the absence of an established name. Literally any written policy for contributing a casing rule, including "don't bother unless you've got a contributor's approval ahead of time", would be an improvement on the current status quo.

@coriolinus
Copy link
Author

The "established name" heuristic is particularly frustrating, given that as of right now, googling for "train case" produces a page about luggage; there are no links to the casing rule on that front page.

@jplatte
Copy link
Collaborator

jplatte commented Oct 25, 2023

I can understand that you're not happy about the absence of a written policy for new casing rules, but this just one of many libraries I maintain in my spare, and generally very low on my list of priorities.

However, it also seems like you are seeing some relation between this crate and serde, and I just want to note that serde ships its own case conversion implementation that has nothing to do with heck.

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

Successfully merging this pull request may close these issues.

2 participants