Function palette::cast::from_array

source ·
pub fn from_array<T>(array: T::Array) -> T
where T: ArrayCast,
Expand description

Cast from an array to a color type.

use palette::{cast, Srgb};

let array = [23, 198, 76];
assert_eq!(cast::from_array::<Srgb<u8>>(array),  Srgb::new(23, 198, 76));

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

use palette::Srgb;

let array = [23, 198, 76];

// Arrays implement `Into`:
let color1: Srgb<u8> = array.into();

// Colors implement `From`:
let color2 = Srgb::from(array);