cosmic::cosmic_theme::palette::cast

Trait 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.

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.

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 as UintCast>::Uint]>) -> &'a [C]

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 as UintCast>::Uint>) -> &'a [C]

Source§

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

Source§

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

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 as UintCast>::Uint]>) -> &'a mut [C]

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 as UintCast>::Uint>) -> &'a mut [C]

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 as UintCast>::Uint]) -> &'a mut [C]

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 as UintCast>::Uint; N]) -> &'a [C]

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 as UintCast>::Uint; N]) -> &'a mut [C]

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

fn from_uints(uints: [<C as UintCast>::Uint; N]) -> [C; N]

Implementors§