Trait cosmic::cosmic_theme::palette::cast::ArraysInto
source · pub trait ArraysInto<C> {
// Required method
fn arrays_into(self) -> C;
}
Expand description
Trait for casting a collection of arrays into 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::ArraysInto, 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]];
let colors: [Srgb<u8>; 2] = array.arrays_into();
assert_eq!(colors, [Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]);
let colors: &[Srgb<u8>] = slice.arrays_into();
assert_eq!(colors, [Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]);
let colors: &mut [Srgb<u8>] = slice_mut.arrays_into();
assert_eq!(colors, [Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]);
let colors: Vec<Srgb<u8>> = vec.arrays_into();
assert_eq!(colors, vec![Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]);
Owning types can be cast as slices, too:
use palette::{cast::ArraysInto, Srgb};
let array: [_; 2] = [[64, 139, 10], [93, 18, 214]];
let mut vec: Vec<_> = vec![[64, 139, 10], [93, 18, 214]];
let colors: &[Srgb<u8>] = (&array).arrays_into();
assert_eq!(colors, [Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]);
let colors: &mut [Srgb<u8>] = (&mut vec).arrays_into();
assert_eq!(colors, [Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]);
Required Methods§
sourcefn arrays_into(self) -> C
fn arrays_into(self) -> C
Cast this collection of arrays into a collection of colors.