palette::cast

Trait UintsAsMut

source
pub trait UintsAsMut<C: ?Sized> {
    // Required method
    fn uints_as_mut(&mut self) -> &mut C;
}
Expand description

Trait for casting a mutable reference to a collection of unsigned integers into a mutable 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::UintsAsMut, rgb::PackedArgb, Srgba};

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

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

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

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

Required Methods§

source

fn uints_as_mut(&mut self) -> &mut C

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

Implementations on Foreign Types§

source§

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

source§

fn uints_as_mut(&mut self) -> &mut [C]

source§

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

source§

fn uints_as_mut(&mut self) -> &mut [C]

source§

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

source§

fn uints_as_mut(&mut self) -> &mut [C]

source§

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

source§

fn uints_as_mut(&mut self) -> &mut [C]

Implementors§