PistonDevelopers/conrod — pull request #122 by cybergeek94 (2014-09-18 09:14:27+00:00)
Title: Implement `Encodable, Decodable` for `Color`.

The implementation of `Encodable` encodes the Color as a length-4 vector of `f32`. `Decodable` expects a length-4 vector of `f32` and errors if it is not the correct length.

I was not able to test the implementation due to unrelated build errors. Though when I work on a fork I haven't touched in a while, I should remember to update the fork before doing anything else. I can attempt to rebase these commits to slim it all down, but I don't think that's a huge concern. At the very least, I eliminated all type-check errors in `color.rs`, so the committed code *should* be correct.

I was pleased to discover that the type-checker treats a reference to a fixed-length vector (e.g. `[f32, ..4]`) the same as a vector slice, so `encode()` was very simple to implement. I figured encoding `Color` as a tuple-struct would only add unnecessary complexity, though it won't be as clear that the object is a color in the encoded representation, if it is human-readable. However, this adds the benefit of allowing any encoded length-4 vector to decode as `Color`, making it easier to use in manually edited config and JSON files.