cosmic::cosmic_theme::palette::cast

Trait ArraysFrom

source
pub trait ArraysFrom<C> {
    // Required method
    fn arrays_from(colors: C) -> Self;
}
Expand description

Trait for casting a collection of arrays from a 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::ArraysFrom, 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!(<[_; 2]>::arrays_from(array), [[64, 139, 10], [93, 18, 214]]);
assert_eq!(<&[_]>::arrays_from(slice), [[64, 139, 10], [93, 18, 214]]);
assert_eq!(<&mut [_]>::arrays_from(slice_mut), [[64, 139, 10], [93, 18, 214]]);
assert_eq!(Vec::<_>::arrays_from(vec), vec![[64, 139, 10], [93, 18, 214]]);

Owning types can be cast as slices, too:

use palette::{cast::ArraysFrom, 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!(<&[_]>::arrays_from(&array), [[64, 139, 10], [93, 18, 214]]);
assert_eq!(<&mut [_]>::arrays_from(&mut vec), [[64, 139, 10], [93, 18, 214]]);

Required Methods§

source

fn arrays_from(colors: C) -> Self

Cast a collection of colors into a collection of arrays.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T, C> ArraysFrom<C> for T
where C: IntoArrays<T>,