I have difficulties reading that. What is *mut _ ? .cast() does type-inference to the function result?
And I thought transmute was compiler checked in this case.
That would add a dependency and I cannot add traits/functions for structs in another crate.
My rgba is quite simple and I need only 2 or 3 functions in the whole program for converting different types of colors.
The more important thing was the blend routine itself.
It feels like processing these pixelblending could be done smarter. In Delphi and C# I believe I used a difficult lookup table, but that will probably not be any faster.
You can add a trait, and that trait can include functions - the extension trait pattern is exactly this.
While the coherence rules aren't trivial, you can treat them as "either the struct I'm implementing the trait for, or the trait I'm implementing, or both, must be defined in this crate" - this rule is slightly stricter than the coherence rules in cases where there are generic parameters involved.
It might be useful to add a fast path for fully-opaque or transparent pixels. On the other hand, the branching control flow might cost more speed than it gains, so you’ll need to benchmark it.