Trait palette::cast::FromUints

source ·
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§

source

fn from_uints(uints: U) -> Self

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

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

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

source§

fn from_uints(uints: &'a Box<[C::Uint]>) -> Self

source§

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

source§

fn from_uints(uints: &'a Vec<C::Uint>) -> Self

source§

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

source§

fn from_uints(uints: &'a [C::Uint]) -> Self

source§

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

source§

fn from_uints(uints: &'a mut Box<[C::Uint]>) -> Self

source§

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

source§

fn from_uints(uints: &'a mut Vec<C::Uint>) -> Self

source§

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

source§

fn from_uints(uints: &'a mut [C::Uint]) -> Self

source§

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

source§

fn from_uints(uints: &'a [C::Uint; N]) -> Self

source§

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

source§

fn from_uints(uints: &'a mut [C::Uint; N]) -> Self

source§

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

source§

fn from_uints(uints: Box<[C::Uint]>) -> Self

source§

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

source§

fn from_uints(uints: Vec<C::Uint>) -> Self

source§

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

source§

fn from_uints(uints: [C::Uint; N]) -> Self

Implementors§