pub fn from_component_array<T, const N: usize, const M: usize>(
values: [<T::Array as ArrayExt>::Item; N],
) -> [T; M]where
T: ArrayCast,
Expand description
Cast from an array of color components to an array of colors.
§Panics
The cast will panic if the length of the input array is not a multiple of the color’s array length. This is unfortunately unavoidable until generic const expressions are stabilized.
No try_*
alternative is provided, since the array size can’t be changed
during runtime.
§Examples
use palette::{cast, Srgb};
let components = [64, 139, 10, 93, 18, 214];
assert_eq!(
cast::from_component_array::<Srgb<u8>, 6, 2>(components),
[Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]
);
This panics:
ⓘ
use palette::{cast, Srgb};
let components = [64, 139, 10, 93, 18]; // Not a multiple of 3
assert_eq!(
cast::from_component_array::<Srgb<u8>, 5, 2>(components),
[Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]
);