pub trait UintsAs<C: ?Sized> {
// Required method
fn uints_as(&self) -> &C;
}
Expand description
Trait for casting a reference to a collection of unsigned integers into a reference to 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::UintsAs, rgb::PackedArgb, Srgba};
let array: [_; 2] = [0xFF17C64C, 0xFF5D12D6];
let slice: &[_] = &[0xFF17C64C, 0xFF5D12D6];
let vec: Vec<_> = vec![0xFF17C64C, 0xFF5D12D6];
let colors: &[PackedArgb] = array.uints_as();
assert_eq!(
colors,
&[
Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
]
);
let colors: &[PackedArgb] = slice.uints_as();
assert_eq!(
colors,
&[
Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
]
);
let colors: &[PackedArgb] = vec.uints_as();
assert_eq!(
colors,
&[
Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
]
);