rust-embedded-community / usb-device

Experimental device-side USB framework for microcontrollers in Rust.
MIT License
413 stars 77 forks source link

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

Closed vitalyvb closed 4 months ago

vitalyvb commented 4 months ago

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.

ryan-summers commented 4 months ago

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