kornelski / rust-rgb

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

Should the pixels implement `Index<usize>` and `IndexMut<usize>` #132

Closed ripytide closed 1 month ago

ripytide commented 1 month ago

My main inspiration is https://github.com/image-rs/image/issues/2259, where the current image pixel types use an internal array like: struct Rgb<T>([T;3]) and also implement Index<usize> and IndexMutso if thergb` crates types also implemented those traits then the migration process would be easier.

On the other hand, using the field access (.r, .g, .b) seems much more readable to me so perhaps we shouldn't implement Index<usize> and instead refactor the image crate to field access when doing the migration.

kornelski commented 1 month ago

No, I think it'd be counter-productive. It would be confusing when working with slices of pixels.

Supporting something like pixel['r'] could be interesting, but that's pretty quirky and niche.