-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add traits for casting collections of colors to and from other data types #338
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Benchmark for 3ae99acClick to view benchmark
|
856326e
to
889578a
Compare
I replaced the generic implementations with specific, but more consistent implementations. Also added doc examples for each trait. |
Benchmark for cff7201Click to view benchmark
|
bors r+ |
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
bors bot
added a commit
that referenced
this pull request
Aug 10, 2023
345: Add `ArraysAs`, `AsArrays`, and corresponding traits for components and uints r=Ogeon a=Ogeon This adds more casting traits, in addition to #338. These traits fulfill the same purpose as `AsRef` and `AsMut`, such as: ```rust use palette::{Srgb, cast::ComponentsAsMut}; let mut image_buffer: Vec<u8> = /* ... */; let color_buffer: &mut [Srgb<u8>] = image_buffer.components_as_mut(); ``` Co-authored-by: Erik Hedvall <erikwhedvall@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
These traits are alternatives to the free functions in
cast
. The idea is to have less "type information" in the naming and only focus on the high level transform. In essence whatFrom
andInto
also does. For example, with these changes:Casting from owned to slice is limited to a fixed set of owning types, since it's hard to cover everything that resembles a slice. Arrays and slices don't implement
Deref<Target=[T]>
, for example, whileAsRef<[T]>
doesn't work for theSelf
type...In addition to that, I also upgraded some actions in the workflows and added Miri checks to CI. It's good to keep an eye on those transmutes and pointer casts and even better to do it automatically. I have only been running it manually so far.