Function palette::cast::from_component_slice

source ·
pub fn from_component_slice<T>(values: &[<T::Array as ArrayExt>::Item]) -> &[T]
where T: ArrayCast,
Expand description

The same as try_from_component_slice but panics on error.

§Panics

The cast will panic if the length of the input slice is not a multiple of the color’s array length.

§Examples

use palette::{cast, Srgb};

let components = &[64, 139, 10, 93, 18, 214];
assert_eq!(
    cast::from_component_slice::<Srgb<u8>>(components),
    &[Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]
)

This panics:

use palette::{cast, Srgb};

let components = &[64, 139, 10, 93, 18, 214, 0, 123]; // Not a multiple of 3
cast::from_component_slice::<Srgb<u8>>(components);