Function palette::cast::from_component_vec
source · pub fn from_component_vec<T>(
values: Vec<<T::Array as ArrayExt>::Item>,
) -> Vec<T>where
T: ArrayCast,
Expand description
The same as try_from_component_vec
but panics on error.
§Panics
The cast will panic if the length or capacity of the input Vec
is not a
multiple of the color’s array length.
§Examples
use palette::{cast, Srgb};
let components = vec![64, 139, 10, 93, 18, 214];
assert_eq!(
cast::from_component_vec::<Srgb<u8>>(components),
vec![Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]
)
This panics due to the incorrect length:
ⓘ
use palette::{cast, Srgb};
// Not a multiple of 3:
let components = vec![64, 139, 10, 93, 18, 214, 0, 123];
cast::from_component_vec::<Srgb<u8>>(components);
This panics due to the incorrect capacity:
ⓘ
use palette::{cast, Srgb};
let mut components = vec![64, 139, 10, 93, 18, 214];
components.reserve_exact(2); // Not a multiple of 3
cast::from_component_vec::<Srgb<u8>>(components);