pub trait AsComponents<C: ?Sized> {
// Required method
fn as_components(&self) -> &C;
}
Expand description
Trait for casting a reference to a collection of colors into a reference to a collection of color components 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::AsComponents, 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 vec: Vec<_> = vec![Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)];
assert_eq!(array.as_components(), &[64, 139, 10, 93, 18, 214]);
assert_eq!(slice.as_components(), &[64, 139, 10, 93, 18, 214]);
assert_eq!(vec.as_components(), &[64, 139, 10, 93, 18, 214]);
Required Methods§
sourcefn as_components(&self) -> &C
fn as_components(&self) -> &C
Cast this collection of colors into a collection of color components.