kornelski / rust-rgb

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

Generalize `iter` on `RGB<T>` and `RGBA<T>` #40

Closed cole-miller closed 3 years ago

cole-miller commented 3 years ago

This PR rewrites the iter methods on RGB<T> and RGBA<T> to return a custom iterator over &T, rather than casting to a slice and then cloning each value. This is in line with the typical behavior of methods named iter e.g. in the standard library. In the common case where T: Copy you can adapt to this change just by inserting .copied(). As a result, these methods no longer require constraining T.

I also fixed the tests in src/lib.rs.

This is a breaking API change and could perhaps be folded into a 1.0 release.

kornelski commented 3 years ago

Is this change possible to do in a backwards-compatible way with the semver trick? I'm afraid that because it modifies an inherent method, it can't be :(

cole-miller commented 3 years ago

I can't see how to do it... I guess another option would be to initially add these as new methods (iter_ref or whatever) and deprecate iter, then complete the shift somewhere down the line.

cole-miller commented 3 years ago

While we're talking about these methods, I was wondering -- how often is RGBA::iter useful? I'm hardly an expert but it seems to me like you'd usually want to treat the alpha channel separately.