Implement bytemuck::Zeroable
and bytemuck::Pod
for every color type
#229
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm working on an experimental creative framework for Rust and I wanted to use one of
palette
types in a uniform buffer. This can be easily done through unsafe code but I think it is much cleaner to use thebytemuck
crate which provide theZeroable
andPod
traits to convert types from and to raw bytes.This pull request implements those traits for the color types defined in this crate.
Changes
I did the whole pull request in a single commit, implementing the traits for the following types.
Rgb<S, T>
whereT
isPod
/Zeroable
Luma<S, T>
whereT
isPod
/Zeroable
Hsl<S, T>
whereT
isPod
/Zeroable
Hsluv<Wp, T>
whereT
isPod
/Zeroable
Hsv<S, T>
whereT
isPod
/Zeroable
Hwb<S, T>
whereT
isPod
/Zeroable
Lab<Wp, T>
whereT
isPod
/Zeroable
Lch<Wp, T>
whereT
isPod
/Zeroable
Lchuv<Wp, T>
whereT
isPod
/Zeroable
Xyz<Wp, T>
whereT
isPod
/Zeroable
Yxy<Wp, T>
whereT
isPod
/Zeroable
Alpha<C, T>
whereC
andT
areZeroable
Alpha<C<T>, T>
whereC<T>
is a color that isPod
andT
isPod
eg.
Alpha<Rgb<T>, T>
isPod
ifT
isPod
I also implemented
Zeroable
andPod
for thePacked<C>
rgba struct. This required to make it implementCopy
regardless of whetherC
wasCopy
.Note
I really expect this change to be used with the
Rgba
/Rgb
types, but I made the change for every color type for consistency.