cosmic::cosmic_theme::palette::cast

Trait UintsAs

source
pub trait UintsAs<C>
where 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()
    ]
);

Required Methods§

source

fn uints_as(&self) -> &C

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

Implementations on Foreign Types§

source§

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

source§

fn uints_as(&self) -> &[C]

source§

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

source§

fn uints_as(&self) -> &[C]

source§

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

source§

fn uints_as(&self) -> &[C]

source§

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

source§

fn uints_as(&self) -> &[C]

Implementors§