pub trait FromUints<U> {
// Required method
fn from_uints(uints: U) -> Self;
}
Expand description
Trait for casting a collection of colors from a collection of unsigned integers 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::FromUints, rgb::PackedArgb, Srgba};
let array: [_; 2] = [0xFF17C64C, 0xFF5D12D6];
let slice: &[_] = &[0xFF17C64C, 0xFF5D12D6];
let slice_mut: &mut [_] = &mut [0xFF17C64C, 0xFF5D12D6];
let vec: Vec<_> = vec![0xFF17C64C, 0xFF5D12D6];
assert_eq!(
<[PackedArgb; 2]>::from_uints(array),
[
Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
]
);
assert_eq!(
<&[PackedArgb]>::from_uints(slice),
[
Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
]
);
assert_eq!(
<&mut [PackedArgb]>::from_uints(slice_mut),
[
Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
]
);
assert_eq!(
Vec::<PackedArgb>::from_uints(vec),
vec![
Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
]
);
Owning types can be cast as slices, too:
use palette::{cast::FromUints, rgb::PackedArgb, Srgba};
let array: [_; 2] = [0xFF17C64C, 0xFF5D12D6];
let mut vec: Vec<_> = vec![0xFF17C64C, 0xFF5D12D6];
assert_eq!(
<&[PackedArgb]>::from_uints(&array),
[
Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
]
);
assert_eq!(
<&mut [PackedArgb]>::from_uints(&mut vec),
[
Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
]
);
Required Methods§
Sourcefn from_uints(uints: U) -> Self
fn from_uints(uints: U) -> Self
Cast a collection of unsigned integers into an collection of colors.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.