kornelski / rust-rgb

struct RGB for sharing pixels between crates
https://lib.rs/rgb
MIT License
97 stars 19 forks source link

Add doc examples to everything and reword normal docs. #103

Closed ripytide closed 2 months ago

ripytide commented 2 months ago

One non-doctest related change was reverting back to ColorArray and ComponentArray associated types which was found to be more flexible than the -> impl ArrayLike return type as it lets the compiler figure out conditional trait impls in non-generic contexts.

For example the color_array() doc-test compiles with the associated types version but not the -> impl ArrayLike version since the compiler can figure out PartialEq is implemented on the first version but not the second:

use rgb::{HetPixel, Rgb, Rgba};

let rgb = Rgb {r: 0_u8, g: 10, b: 100};
let rgba = Rgba {r: 0_u8, g: 10, b: 100, a: 50};

assert_eq!(rgb.color_array(), [0, 10, 100]);
assert_eq!(rgba.color_array(), [0, 10, 100]);

I also added an implementation of PixelComponent for bool which would possibly be used for binary images with Gray<bool>.

The README.md usage section was also updated to show the new traits and how they can be used.