cosmic::cosmic_theme::palette::cast

Trait ArraysAs

source
pub trait ArraysAs<C>
where C: ?Sized,
{ // Required method fn arrays_as(&self) -> &C; }
Expand description

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

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

let colors: &[Srgb<u8>] = array.arrays_as();
assert_eq!(colors, &[Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]);

let colors: &[Srgb<u8>] = slice.arrays_as();
assert_eq!(colors, &[Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]);

let colors: &[Srgb<u8>] = vec.arrays_as();
assert_eq!(colors, &[Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]);

Required Methods§

source

fn arrays_as(&self) -> &C

Cast this collection of arrays into a collection of colors.

Implementations on Foreign Types§

source§

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

source§

fn arrays_as(&self) -> &[C]

source§

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

source§

fn arrays_as(&self) -> &[C]

source§

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

source§

fn arrays_as(&self) -> &[C]

source§

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

source§

fn arrays_as(&self) -> &[C]

Implementors§