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

Convert LangID from u16 enum to tuple struct containing u16 #141

Merged
merged 2 commits into from
Feb 28, 2024
Merged

Conversation

vitalyvb
Copy link
Contributor

Relax lang_id checks provided by enum so that any lang_id could be used, not only values listed in the enum. These checks increased the code size considerably without much benefit. Resolves #139.

Language identifiers like LangID::EN_US have a new type, but this should not require source code changes in a code which uses them.

Provide two traits to convert LangID to and from u16 freely. This implicitly provides TryFrom trait which previously was derived using TryFromPrimitive.

There's no special constructor for LangID for values outside of the provided constants, but it can be converted from any u16.

As TryFromPrimitive in no longer used, remove num_enum dependency.

vitalyvb and others added 2 commits February 18, 2024 19:54
Relax lang_id checks provided by enum so that any lang_id could be
used, not only values listed in the enum. These checks increased
the code size considerably without much benefit. Resolves #139.

Language identifiers like LangID::EN_US have a new type, but this
should not require source code changes in a code which uses them.

Provide two traits to convert LangID to and from u16 freely. This
implicitly provides TryFrom trait which previously was derived
using TryFromPrimitive.

There's no special constructor for LangID for values outside of
the provided constants, but it can be converted from any u16.

As TryFromPrimitive in no longer used, remove num_enum dependency.
Copy link
Member

@ryan-summers ryan-summers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR, I was just starting to look into this and forgot someone had submitted a PR for it already.

While this isn't technically a semver-compatible change without bumping the minor version (since some of the LangID API has changed), I don't think anyone was actively using that API since it was rather new. Given that, I'm fine just releasing this as a patch version and we can yank it later if it causes anyone trouble.

We need a CHANGELOG entry here, but I don't mind adding it myself later. Thanks for doing the leg work here. I'm going to test it out on some hardware and merge if it works :)

@ryan-summers ryan-summers merged commit 2dbba84 into rust-embedded-community:master Feb 28, 2024
3 checks passed
@ryan-summers
Copy link
Member

It worked great for me and definitely reduced the code size by 8KB upon analysis. Thanks for the change!

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.

Improvement: Minimize LANGID enum under feature flag
2 participants