Trait palette::cast::IntoUints

source ·
pub trait IntoUints<U> {
    // Required method
    fn into_uints(self) -> U;
}
Expand description

Trait for casting a collection of colors into 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::IntoUints, rgb::PackedArgb, Srgba};

let array: [PackedArgb; 2] = [
    Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
    Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
];
let slice: &[PackedArgb] = &[
    Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
    Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
];
let slice_mut: &mut [PackedArgb] = &mut [
    Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
    Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
];
let vec: Vec<PackedArgb> = vec![
    Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
    Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
];

assert_eq!(array.into_uints(), [0xFF17C64C, 0xFF5D12D6]);
assert_eq!(slice.into_uints(), [0xFF17C64C, 0xFF5D12D6]);
assert_eq!(slice_mut.into_uints(), [0xFF17C64C, 0xFF5D12D6]);
assert_eq!(vec.into_uints(), vec![0xFF17C64C, 0xFF5D12D6]);

Owning types can be cast as slices, too:

use palette::{cast::IntoUints, rgb::PackedArgb, Srgba};

let array: [PackedArgb; 2] = [
    Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
    Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
];
let mut vec: Vec<PackedArgb> = vec![
    Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
    Srgba::new(0x5D, 0x12, 0xD6, 0xFF).into()
];

assert_eq!((&array).into_uints(), [0xFF17C64C, 0xFF5D12D6]);
assert_eq!((&mut vec).into_uints(), [0xFF17C64C, 0xFF5D12D6]);

Required Methods§

source

fn into_uints(self) -> U

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

Implementations on Foreign Types§

source§

impl<'a, C> IntoUints<&'a [<C as UintCast>::Uint]> for &'a [C]
where C: UintCast,

source§

fn into_uints(self) -> &'a [C::Uint]

source§

impl<'a, C> IntoUints<&'a [<C as UintCast>::Uint]> for &'a Box<[C]>
where C: UintCast,

source§

fn into_uints(self) -> &'a [C::Uint]

source§

impl<'a, C> IntoUints<&'a [<C as UintCast>::Uint]> for &'a Vec<C>
where C: UintCast,

source§

fn into_uints(self) -> &'a [C::Uint]

source§

impl<'a, C> IntoUints<&'a mut [<C as UintCast>::Uint]> for &'a mut [C]
where C: UintCast,

source§

fn into_uints(self) -> &'a mut [C::Uint]

source§

impl<'a, C> IntoUints<&'a mut [<C as UintCast>::Uint]> for &'a mut Box<[C]>
where C: UintCast,

source§

fn into_uints(self) -> &'a mut [C::Uint]

source§

impl<'a, C> IntoUints<&'a mut [<C as UintCast>::Uint]> for &'a mut Vec<C>
where C: UintCast,

source§

fn into_uints(self) -> &'a mut [C::Uint]

source§

impl<'a, C, const M: usize> IntoUints<&'a [<C as UintCast>::Uint]> for &'a [C; M]
where C: UintCast,

source§

fn into_uints(self) -> &'a [C::Uint]

source§

impl<'a, C, const M: usize> IntoUints<&'a mut [<C as UintCast>::Uint]> for &'a mut [C; M]
where C: UintCast,

source§

fn into_uints(self) -> &'a mut [C::Uint]

source§

impl<C> IntoUints<Box<[<C as UintCast>::Uint]>> for Box<[C]>
where C: UintCast,

source§

fn into_uints(self) -> Box<[C::Uint]>

source§

impl<C> IntoUints<Vec<<C as UintCast>::Uint>> for Vec<C>
where C: UintCast,

source§

fn into_uints(self) -> Vec<C::Uint>

source§

impl<C, const N: usize> IntoUints<[<C as UintCast>::Uint; N]> for [C; N]
where C: UintCast,

source§

fn into_uints(self) -> [C::Uint; N]

Implementors§