icu4x icon indicating copy to clipboard operation
icu4x copied to clipboard

Use open_enum for enumerated properties

Open kupiakos opened this issue 3 years ago • 3 comments

The pattern of using an integer newtype with named associated constants is exactly what the open_enum macro aims to make cleaner. This pull should result in no semantic change. All values have stayed the same; the syntax has just changed. I've also moved some comments to docstrings.

I think it looks cleaner and I aimed to make open-enum a small dependency appropriate for icu4x - what are your thoughts?

kupiakos avatar Sep 12 '22 01:09 kupiakos

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Sep 12 '22 01:09 CLAassistant

Personally I'm in favor of this dependency; it's a build-time only dep and it doesn't add deps other than itself. @sffc ?

Manishearth avatar Sep 12 '22 02:09 Manishearth

Personally I'm in favor of this dependency; it's a build-time only dep and it doesn't add deps other than itself. @sffc ?

It's a fine dependency to add from my perspective

sffc avatar Sep 12 '22 17:09 sffc

Notice: the branch changed across the force-push!

  • Cargo.lock is different
  • components/properties/Cargo.toml is different
  • components/properties/src/props.rs is different

View Diff Across Force-Push

~ Your Friendly Jira-GitHub PR Checker Bot

I just rebased against main due to a merge conflict - hopefully that's OK with your review workflow. Apparently Github handles this a lot less well than Gerrit.

kupiakos avatar Oct 14 '22 17:10 kupiakos

I just rebased against main due to a merge conflict - hopefully that's OK with your review workflow. Apparently Github handles this a lot less well than Gerrit.

It's fine for smaller PRs; if there's a PR with a lot of line-specific comments, we tend to prefer merge commits over rebases, because they will get lost. We have the bot that posts when a force-push is made for better visibility.

sffc avatar Oct 14 '22 18:10 sffc

I don't have a strong opinion here. Trusting @nordzilla assessment.

zbraniecki avatar Oct 14 '22 18:10 zbraniecki

Until "real" open enums become a part of the language, is there an advantage to this abstraction aside from readability?

No, other than me being happy to see an explicitly open enum (and my own macro) in major production code. 🙂

I'm also working on an RFC for open enums in the language (by specifying #[repr(transparent)]), but it'd be a breaking change to eventually switch to it since it is not constructed/accessed the same.

kupiakos avatar Oct 15 '22 01:10 kupiakos

Discussion with @sffc @zbraniecki @Manishearth at ICU4X-SC:

ICU4X has a dependency problem; we should be very critical of taking dependencies. We can currently claim that almost all of our dependencies are ICU4X itself. All exceptions to that are dependencies that add a lot of value and are used broadly, like postcard and displaydoc. There is not consensus that open_enum as a standalone crate rises to that bar. However, we're very much looking forward to using open_enum when it gets standardized.

sffc avatar Nov 10 '22 19:11 sffc