kornelski / rust-rgb

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

feat: add checked_{add,sub} methods #60

Closed RRRadicalEdward closed 4 months ago

RRRadicalEdward commented 4 months ago

This PR adds RGB::checked_add and RGB::checked_sub method. Do I need to add the methods for other pixels types (RGBA, etc)?

kornelski commented 4 months ago

There's no standard trait for checked operations, so unfortunately this will be pretty verbose and always incomplete.

I'm not sure if it's worth it over using .map().

RRRadicalEdward commented 4 months ago

I understand your point. Yes, there are no traits for checked operations, but I feel as if the RGB types behave like primitive types from std, most of which have checked_add/checked_sub functions so It makes sense for RGB<u8>, RGB<u16>, RGB<u32>, etc to have it as well whatever there's a trait or not for it because it mimics the std.