Trait palette::cast::UintsInto

source ·
pub trait UintsInto<C> {
    // Required method
    fn uints_into(self) -> C;
}
Expand description

Trait for casting a collection of unsigned integers into 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::UintsInto, 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];

let colors: [PackedArgb; 2] = array.uints_into();
assert_eq!(colors, [
    Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
    Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
]);

let colors: &[PackedArgb] = slice.uints_into();
assert_eq!(colors, [
    Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
    Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
]);

let colors: &mut [PackedArgb] = slice_mut.uints_into();
assert_eq!(colors, [
    Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
    Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
]);

let colors: Vec<PackedArgb> = vec.uints_into();
assert_eq!(colors, 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::UintsInto, rgb::PackedArgb, Srgba};

let array: [_; 2] = [0xFF17C64C, 0xFF5D12D6];
let mut vec: Vec<_> = vec![0xFF17C64C, 0xFF5D12D6];

let colors: &[PackedArgb] = (&array).uints_into();
assert_eq!(colors, [
    Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
    Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
]);

let colors: &mut [PackedArgb] = (&mut vec).uints_into();
assert_eq!(colors, [
    Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
    Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
]);

Required Methods§

source

fn uints_into(self) -> C

Cast this collection of unsigned integers into a collection of colors.

Implementors§

source§

impl<C, U> UintsInto<C> for U
where C: FromUints<U>,