Function cosmic::cosmic_theme::palette::cast::try_from_component_slice_mut
source · pub fn try_from_component_slice_mut<T>(
values: &mut [<<T as ArrayCast>::Array as ArrayExt>::Item],
) -> Result<&mut [T], SliceCastError>where
T: ArrayCast,
Expand description
Cast from a mutable slice of color components to a slice of colors.
§Errors
The cast will return an error if the length of the input slice is not a multiple of the color’s array length.
§Examples
use palette::{cast, Srgb};
let components = &mut [64, 139, 10, 93, 18, 214];
assert_eq!(
cast::try_from_component_slice_mut::<Srgb<u8>>(components),
Ok([Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)].as_mut())
)
This produces an error:
use palette::{cast, Srgb};
let components = &mut [64, 139, 10, 93, 18]; // Not a multiple of 3
assert!(cast::try_from_component_slice_mut::<Srgb<u8>>(components).is_err());