Closed Diablo-D3 closed 2 years ago
Hi, thanks for bringing this up. Before diving deeper into this, it looks from your error message like the input is &Oklch
, so a reference. Is this the case in the actual code? Conversion is not implemented for references, and that could be the reason.
Ahh, sorry. Throwing a *
in fixed it. I'm new to rust, and I'm not quite used to how often I have to ref/deref compared to idiomatic C. I'm going to close this issue, but I wonder if it would benefit Palette to also implement conversion for references, given how an obvious use case would be colors stored in slices or hashmaps or similar.
No worries, it can take some time to get used to. The fact that it's an input type to a trait doesn't make it simpler. It's good that you asked, in case it was an issue with the library! Oklab and Oklch have some extra requirements, after all.
Implementing the conversion traits for references could definitely be possible. The downside is that it would need an implicit .clone()
to create an ownend value, unless it's restricted to T: Copy
. It's a minor issue in practice, since most people use u8
and f32
values, but experience has taught me to push decisions like copying to the caller to avoid nasty surprises.
For cases where there are stored colors that need to be modified (like an array), the next version of Palette will have some neat changes for colors behind &mut
references. Including temporary and permanent in-place conversion of the whole array in many cases. No ETA, though!
Conversion to Srgb from Oklch is not implemented, Oklch from Srgb is
How To Reproduce
Actual Outcome
Additional Details
palette = { version = "0.6.0", features = ["serializing"] }