kornelski / rust-rgb

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

Add convience methods for bytemuck conversions #120

Open ripytide opened 1 month ago

ripytide commented 1 month ago

From #64

Convenience methods for bytemuck? slice.as_rgba() vs bytemuck::cast_slice::<Rgba<u8>>(slice)

Personally, I don't think using bytemuck is that bad as it is more explicit and ideally you would only be doing bit-casts when transferring data in or out of a strongly typed rust system so it shouldn't come up that often.

kornelski commented 2 weeks ago

It's not terrible, but looks odd when everything else is a trait/method:

https://github.com/kornelski/lodepng-rust/commit/41b85c525452f0c08672393e0a1d98951c5da925

ripytide commented 2 weeks ago

I'm not opposed to creating a helper trait for postfix bytemucking, but shouldn't that belong in the bytemuck crate rather than in this crate? You could just implement the helper trait locally in the crate you want to use it in, but I imagine that might become a maintenance burden if you have multiple crates where you'd like to use it. Perhaps a small helper crate?