Hello, I am converting a diver for a i2c display, and to communicate it I need to use a series of set values.
For instance, in the Python driver, colours are defined as:
REG_RED = 0x04
REG_GREEN = 0x03
REG_BLUE = 0x02
REG_MODE1 = 0x00
....
On the surface this seems like an ideal use case for enums to provide transparent human readable representations, but I don't know how to construct an enum with set conversions cleanly.
I was thinking of doing
impl From<color_enum> for u8 {
fn from(color: color_enum) -> Self {
match color {
REG_RED => { 0x04 as u8}
......
But this seems very clunky, and that there should be a more easily readable way to achieve the same.
Priority is on the most clean looking final code in usage (for instance making u8 Vecs of these values).
Any and all help is appreciated, thanks!
