Function cosmic::cosmic_theme::palette::cast::into_component_array

source ·
pub fn into_component_array<T, const N: usize, const M: usize>(
    values: [T; N],
) -> [<<T as ArrayCast>::Array as ArrayExt>::Item; M]
where T: ArrayCast,
Expand description

Cast from an array of colors to an array of color components.

§Panics

It’s unfortunately not able to infer the length of the component array, until generic const expressions are stabilized. In the meantime, it’s going to panic if M isn’t N * T::Array::LENGTH. A future version will remove the M parameter and make the mismatch a compiler error.

No try_* alternative is provided, since the array size can’t be changed during runtime.

§Examples

use palette::{cast, Srgb};

let colors = [Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)];
assert_eq!(cast::into_component_array(colors), [64, 139, 10, 93, 18, 214])

It panics when the array lengths don’t match up:

use palette::{cast, Srgb};

let colors = [Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)];
assert_eq!(cast::into_component_array(colors), [64, 139, 10]) // Too short