pub trait ArraysAs<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)]);