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.

Object Safety§

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§