pub trait FromArrays<A> {
// Required method
fn from_arrays(arrays: A) -> Self;
}
Expand description
Trait for casting a collection of colors from 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::FromArrays, 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]];
assert_eq!(
<[Srgb<u8>; 2]>::from_arrays(array),
[Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]
);
assert_eq!(
<&[Srgb<u8>]>::from_arrays(slice),
[Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]
);
assert_eq!(
<&mut [Srgb<u8>]>::from_arrays(slice_mut),
[Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]
);
assert_eq!(
Vec::<Srgb<u8>>::from_arrays(vec),
vec![Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]
);
Owning types can be cast as slices, too:
use palette::{cast::FromArrays, Srgb};
let array: [_; 2] = [[64, 139, 10], [93, 18, 214]];
let mut vec: Vec<_> = vec![[64, 139, 10], [93, 18, 214]];
assert_eq!(
<&[Srgb<u8>]>::from_arrays(&array),
[Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]
);
assert_eq!(
<&mut [Srgb<u8>]>::from_arrays(&mut vec),
[Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]
);
Required Methods§
sourcefn from_arrays(arrays: A) -> Self
fn from_arrays(arrays: A) -> Self
Cast a collection of arrays into an collection of colors.
Object Safety§
This trait is not object safe.