In my process of learning Rust I have come across a problem that I don't know how to solve elegantly. I want to do operations on Image::Rgb data, but I get the error that they are not implemented. For example:
let rgb = Rgb([40u8, 40, 40]);
let val: u8 = 60;
val*rgb;
Results in the trait Mul<Rgb<u8>> is not implemented for u8
. Of course I can do:
rgb.map(|x| x * val);
But that results in a mess if there are more operations/several rgb colors. Is there any workaround here? How can I implement that Mul
trait?
Edit for reference: I have three points (v1, v2, v3) and a color per point. I want to interpolate the color in between the points, just like here (the color_p formula). Then not only do I have to do three multiplications but also summing and division. I think map
too complicated in that case.