palette::cast

Function into_array_ref

source
pub fn into_array_ref<T>(value: &T) -> &T::Array
where T: ArrayCast,
Expand description

Cast from a color type reference to an array reference.

use palette::{cast, Srgb};

let color = Srgb::new(23u8, 198, 76);
assert_eq!(cast::into_array_ref(&color), &[23, 198, 76]);

It’s also possible to use From, Into and AsRef when casting built-in types:

use palette::Srgb;

let color = Srgb::new(23u8, 198, 76);

// Colors implement `AsRef`:
let array1: &[_; 3] = color.as_ref();

// Color references implement `Into`:
let array2: &[_; 3] = (&color).into();
// Array references implement `From`:
let array3 = <&[_; 3]>::from(&color);