palette::cast

Trait ArraysAsMut

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

Trait for casting a mutable reference to collection of arrays into a mutable reference to 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::ArraysAsMut, Srgb};

let mut array: [_; 2] = [[64, 139, 10], [93, 18, 214]];
let slice_mut: &mut [_] = &mut [[64, 139, 10], [93, 18, 214]];
let mut vec: Vec<_> = vec![[64, 139, 10], [93, 18, 214]];

let colors: &mut [Srgb<u8>] = array.arrays_as_mut();
assert_eq!(colors, &mut [Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]);

let colors: &mut [Srgb<u8>] = slice_mut.arrays_as_mut();
assert_eq!(colors, &mut [Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]);

let colors: &mut [Srgb<u8>] = vec.arrays_as_mut();
assert_eq!(colors, &mut [Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)]);

Required Methods§

source

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

Cast this collection of arrays into a mutable collection of colors.

Implementations on Foreign Types§

source§

impl<'a, T, C, const N: usize> ArraysAsMut<[C]> for Box<[[T; N]]>
where C: ArrayCast<Array = [T; N]>,

source§

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

source§

impl<'a, T, C, const N: usize> ArraysAsMut<[C]> for Vec<[T; N]>
where C: ArrayCast<Array = [T; N]>,

source§

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

source§

impl<'a, T, C, const N: usize> ArraysAsMut<[C]> for [[T; N]]
where C: ArrayCast<Array = [T; N]>,

source§

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

source§

impl<'a, T, C, const N: usize, const M: usize> ArraysAsMut<[C]> for [[T; N]; M]
where C: ArrayCast<Array = [T; N]>,

source§

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

Implementors§