Function cosmic::cosmic_theme::palette::cast::from_array_ref
source · pub fn from_array_ref<T>(value: &<T as ArrayCast>::Array) -> &Twhere
T: ArrayCast,
Expand description
Cast from an array reference to a color type reference.
use palette::{cast, Srgb};
let array = [23, 198, 76];
assert_eq!(cast::from_array_ref::<Srgb<u8>>(&array), &Srgb::new(23, 198, 76));
It’s also possible to use From
, Into
and AsRef
when casting built-in
types:
use palette::Srgb;
let array = [23, 198, 76];
// Arrays implement `AsRef`:
let color1: &Srgb<u8> = array.as_ref();
// Array references implement `Into`:
let color2: &Srgb<u8> = (&array).into();
// Color references implement `From`:
let color3 = <&Srgb<u8>>::from(&array);