cosmic::cosmic_theme::palette::cast

Trait FromArrays

Source
pub trait FromArrays<A> {
    // Required method
    fn from_arrays(arrays: A) -> Self;
}
Expand description

Trait for casting a collection of colors from a collection of arrays without copying.

This trait is meant as a more convenient alternative to the free functions in cast, to allow method chaining among other things.

§Examples

use palette::{cast::FromArrays, Srgb};

let array: [_; 2] = [[64, 139, 10], [93, 18, 214]];
let slice: &[_] = &[[64, 139, 10], [93, 18, 214]];
let slice_mut: &mut [_] = &mut [[64, 139, 10], [93, 18, 214]];
let vec: Vec<_> = vec![[64, 139, 10], [93, 18, 214]];

assert_eq!(
    <[Srgb<u8>; 2]>::from_arrays(array),
    [Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]
);

assert_eq!(
    <&[Srgb<u8>]>::from_arrays(slice),
    [Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]
);

assert_eq!(
    <&mut [Srgb<u8>]>::from_arrays(slice_mut),
    [Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]
);

assert_eq!(
    Vec::<Srgb<u8>>::from_arrays(vec),
    vec![Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]
);

Owning types can be cast as slices, too:

use palette::{cast::FromArrays, Srgb};

let array: [_; 2] = [[64, 139, 10], [93, 18, 214]];
let mut vec: Vec<_> = vec![[64, 139, 10], [93, 18, 214]];

assert_eq!(
    <&[Srgb<u8>]>::from_arrays(&array),
    [Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]
);

assert_eq!(
    <&mut [Srgb<u8>]>::from_arrays(&mut vec),
    [Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]
);

Required Methods§

Source

fn from_arrays(arrays: A) -> Self

Cast a collection of arrays into an collection of colors.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a, T, C, const N: usize> FromArrays<&'a Box<[[T; N]]>> for &'a [C]
where C: ArrayCast<Array = [T; N]>,

Source§

fn from_arrays(arrays: &'a Box<[[T; N]]>) -> &'a [C]

Source§

impl<'a, T, C, const N: usize> FromArrays<&'a Vec<[T; N]>> for &'a [C]
where C: ArrayCast<Array = [T; N]>,

Source§

fn from_arrays(arrays: &'a Vec<[T; N]>) -> &'a [C]

Source§

impl<'a, T, C, const N: usize> FromArrays<&'a [[T; N]]> for &'a [C]
where C: ArrayCast<Array = [T; N]>,

Source§

fn from_arrays(arrays: &'a [[T; N]]) -> &'a [C]

Source§

impl<'a, T, C, const N: usize> FromArrays<&'a mut Box<[[T; N]]>> for &'a mut [C]
where C: ArrayCast<Array = [T; N]>,

Source§

fn from_arrays(arrays: &'a mut Box<[[T; N]]>) -> &'a mut [C]

Source§

impl<'a, T, C, const N: usize> FromArrays<&'a mut Vec<[T; N]>> for &'a mut [C]
where C: ArrayCast<Array = [T; N]>,

Source§

fn from_arrays(arrays: &'a mut Vec<[T; N]>) -> &'a mut [C]

Source§

impl<'a, T, C, const N: usize> FromArrays<&'a mut [[T; N]]> for &'a mut [C]
where C: ArrayCast<Array = [T; N]>,

Source§

fn from_arrays(arrays: &'a mut [[T; N]]) -> &'a mut [C]

Source§

impl<'a, T, C, const N: usize, const M: usize> FromArrays<&'a [[T; N]; M]> for &'a [C]
where C: ArrayCast<Array = [T; N]>,

Source§

fn from_arrays(arrays: &'a [[T; N]; M]) -> &'a [C]

Source§

impl<'a, T, C, const N: usize, const M: usize> FromArrays<&'a mut [[T; N]; M]> for &'a mut [C]
where C: ArrayCast<Array = [T; N]>,

Source§

fn from_arrays(arrays: &'a mut [[T; N]; M]) -> &'a mut [C]

Source§

impl<T, C, const N: usize> FromArrays<Box<[[T; N]]>> for Box<[C]>
where C: ArrayCast<Array = [T; N]>,

Source§

fn from_arrays(arrays: Box<[[T; N]]>) -> Box<[C]>

Source§

impl<T, C, const N: usize> FromArrays<Vec<[T; N]>> for Vec<C>
where C: ArrayCast<Array = [T; N]>,

Source§

fn from_arrays(arrays: Vec<[T; N]>) -> Vec<C>

Source§

impl<T, C, const N: usize, const M: usize> FromArrays<[[T; N]; M]> for [C; M]
where C: ArrayCast<Array = [T; N]>,

Implementors§