You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
254: Replace the `Pixel` trait with `ArrayCast` and cast functions and increase the MSRV to 1.51.0 r=Ogeon a=Ogeon
This replaces the `Pixel` trait with a new system for casting that is based on fixed size arrays as a primitive representation. The initial implementation covers most of the use cases for `Pixel` and some additional features (casting `Box<[T]>` and `Vec<T>` for example). The missing feature is the implicit truncation `Pixel` did. The new system leaves it to the user to truncate collections where necessary.
I couldn't come up with a good trait system that would be universal enough, so I decided to start with this setup with free functions. It will at least give us the base to build something more convenient on.
See https://github.com/Ogeon/palette/discussions/227 for some background and an earlier solution idea.
## Breaking Change
This removes the `Pixel` and `RawPixel` traits and replaces it with a system that is based on the `ArrayCast` marker trait and a number of primitive cast functions.
* Single color casting is available through `From`, `Into`, `AsRef`, `AsMut`, `TryFrom` and `TryInto`.
* Slices and `Vec` can currently only be cast via the functions in the `cast` module. Something more ergonomic may come in a later change.
The MSRV is bumped to 1.51.0 to get access to const generics.
Co-authored-by: Erik Hedvall <erikwhedvall@gmail.com>
Copy file name to clipboardexpand all lines: README.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ A color management and conversion library that focuses on maintaining correctnes
15
15
16
16
## Minimum Supported Rust Version (MSRV)
17
17
18
-
This version of Palette has been automatically tested with Rust version `1.48.0` and the `stable`, `beta`, and `nightly` channels. Future versions of the library may advance the minimum supported version to make use of new language features, but this will be considered a breaking change.
18
+
This version of Palette has been automatically tested with Rust version `1.51.0` and the `stable`, `beta`, and `nightly` channels. Future versions of the library may advance the minimum supported version to make use of new language features, but this will be considered a breaking change.
Copy file name to clipboardexpand all lines: palette/README.md
+9-9
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ A color management and conversion library that focuses on maintaining correctnes
16
16
17
17
## Minimum Supported Rust Version (MSRV)
18
18
19
-
This version of Palette has been automatically tested with Rust version `1.48.0` and the `stable`, `beta`, and `nightly` channels. Future versions of the library may advance the minimum supported version to make use of new language features, but this will be considered a breaking change.
19
+
This version of Palette has been automatically tested with Rust version `1.51.0` and the `stable`, `beta`, and `nightly` channels. Future versions of the library may advance the minimum supported version to make use of new language features, but this will be considered a breaking change.
20
20
21
21
## Getting Started
22
22
@@ -93,16 +93,16 @@ A longer and more advanced example that shows how to implement the conversion tr
93
93
94
94
### Pixels And Buffers
95
95
96
-
When working with image or pixel buffers, or any color type that can be converted to a slice of components (ex. `&[u8]`), the `Pixel` trait provides methods for turning them into slices of Palette colors without cloning the whole buffer:
96
+
When working with image or pixel buffers, or any color type that can be converted to a slice of components (ex. `&[u8]`), the `cast` module provides functions for turning them into slices of Palette colors without cloning the whole buffer:
97
97
98
98
```rust
99
-
usepalette::{Srgb, Pixel};
99
+
usepalette::{cast, Srgb};
100
100
101
101
// The input to this function could be data from an image file or
102
102
// maybe a texture in a game.
103
103
fnswap_red_and_blue(my_rgb_image:&mut [u8]) {
104
104
// Convert `my_rgb_image` into `&mut [Srgb<u8>]` without copying.
0 commit comments