kornelski / rust-rgb

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

Switch to const generic arrays instead of slices. #66

Closed ripytide closed 3 months ago

ripytide commented 3 months ago

Now that const_generics is stable I propose for v0.9 we switch to using const_generics in the definition of the Pixel trait to return arrays rather than slices. Something like:

pub trait Pixel<S, const N: usize> {
    fn subpixels(&self) -> &[S; N];
    fn subpixels_mut(&self) -> &mut [S; N];
}

Since &[S: N] arrays can be trivially converted to &[S] slices (using as_slice() or From/Into) but not vice versa (requires TryFrom) this is strictly more powerful than returning slices.