Trait palette::cast::IntoArrays

source ·
pub trait IntoArrays<A> {
    // Required method
    fn into_arrays(self) -> A;
}
Expand description

Trait for casting a collection of colors into 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::IntoArrays, Srgb};

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

assert_eq!(array.into_arrays(), [[64, 139, 10], [93, 18, 214]]);
assert_eq!(slice.into_arrays(), [[64, 139, 10], [93, 18, 214]]);
assert_eq!(slice_mut.into_arrays(), [[64, 139, 10], [93, 18, 214]]);
assert_eq!(vec.into_arrays(), vec![[64, 139, 10], [93, 18, 214]]);

Owning types can be cast as slices, too:

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

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

assert_eq!((&array).into_arrays(), [[64, 139, 10], [93, 18, 214]]);
assert_eq!((&mut vec).into_arrays(), [[64, 139, 10], [93, 18, 214]]);

Required Methods§

source

fn into_arrays(self) -> A

Cast this collection of colors into a collection of arrays.

Implementations on Foreign Types§

source§

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

source§

fn into_arrays(self) -> &'a [[T; N]]

source§

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

source§

fn into_arrays(self) -> &'a [[T; N]]

source§

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

source§

fn into_arrays(self) -> &'a [[T; N]]

source§

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

source§

fn into_arrays(self) -> &'a mut [[T; N]]

source§

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

source§

fn into_arrays(self) -> &'a mut [[T; N]]

source§

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

source§

fn into_arrays(self) -> &'a mut [[T; N]]

source§

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

source§

fn into_arrays(self) -> &'a [[T; N]]

source§

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

source§

fn into_arrays(self) -> &'a mut [[T; N]]

source§

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

source§

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

source§

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

Implementors§