smart-leds-rs / smart-leds

The end user crate for smart leds (like ws2812)
Apache License 2.0
89 stars 13 forks source link

Make named colors Deserialize #16

Closed cyril-marpaud closed 8 months ago

cyril-marpaud commented 1 year ago

Hello :) First of all, thank you for smart-leds, it's very convenient !

I'm using it in an embedded project that sends commands to an LED strip over Wifi/MQTT. I thus need to deserialize colors. You can check out the ugly From impl that allows me to do so for now.

Would it be possible to implement what's needed to "natively" deserialize named-colors directly from you crate, rather than having to implement that manually ?

Thank you, have a nice day !

david-sawatzke commented 1 year ago

Since the colors are just constants, there is no easy way to get them into serde (as opposed to an enum based implementation). Moving them to enum would make it easier, but means that they don't aren't RGB8 values anymore and would have to somehow be converted when used (probably std::ops::Deref?). I don't think that's worth it, but maybe there are better ways?

I'm not opposed to including an optional serde feature, but think it's only worth it when the resulting code is kept simple & small.