Trait cosmic::cosmic_theme::palette::cast::IntoComponents

source ·
pub trait IntoComponents<C> {
    // Required method
    fn into_components(self) -> C;
}
Expand description

Trait for casting a collection of colors into a collection of color components 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::IntoComponents, Srgb};

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

assert_eq!(array.into_components(), [64, 139, 10, 93, 18, 214]);
assert_eq!(slice.into_components(), [64, 139, 10, 93, 18, 214]);
assert_eq!(slice_mut.into_components(), [64, 139, 10, 93, 18, 214]);
assert_eq!(vec.into_components(), vec![64, 139, 10, 93, 18, 214]);

Owning types can be cast as slices, too:

use palette::{cast::IntoComponents, Srgb};

let array: [_; 2] = [Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)];
let mut vec: Vec<_> = vec![Srgb::new(64u8, 139, 10), Srgb::new(93, 18, 214)];

assert_eq!((&array).into_components(), [64, 139, 10, 93, 18, 214]);
assert_eq!((&mut vec).into_components(), [64, 139, 10, 93, 18, 214]);

Required Methods§

source

fn into_components(self) -> C

Cast this collection of colors into a collection of color components.

Implementations on Foreign Types§

source§

impl<'a, T, C> IntoComponents<&'a [T]> for &'a [C]
where T: 'a, C: ArrayCast, <C as ArrayCast>::Array: ArrayExt<Item = T>,

source§

impl<'a, T, C> IntoComponents<&'a [T]> for &'a Box<[C]>
where T: 'a, C: ArrayCast, <C as ArrayCast>::Array: ArrayExt<Item = T>,

source§

impl<'a, T, C> IntoComponents<&'a [T]> for &'a Vec<C>
where T: 'a, C: ArrayCast, <C as ArrayCast>::Array: ArrayExt<Item = T>,

source§

impl<'a, T, C> IntoComponents<&'a mut [T]> for &'a mut [C]
where T: 'a, C: ArrayCast, <C as ArrayCast>::Array: ArrayExt<Item = T>,

source§

fn into_components(self) -> &'a mut [T]

source§

impl<'a, T, C> IntoComponents<&'a mut [T]> for &'a mut Box<[C]>
where T: 'a, C: ArrayCast, <C as ArrayCast>::Array: ArrayExt<Item = T>,

source§

fn into_components(self) -> &'a mut [T]

source§

impl<'a, T, C> IntoComponents<&'a mut [T]> for &'a mut Vec<C>
where T: 'a, C: ArrayCast, <C as ArrayCast>::Array: ArrayExt<Item = T>,

source§

fn into_components(self) -> &'a mut [T]

source§

impl<'a, T, C, const N: usize> IntoComponents<&'a [T]> for &'a [C; N]
where T: 'a, C: ArrayCast, <C as ArrayCast>::Array: ArrayExt<Item = T>,

source§

impl<'a, T, C, const N: usize> IntoComponents<&'a mut [T]> for &'a mut [C; N]
where T: 'a, C: ArrayCast, <C as ArrayCast>::Array: ArrayExt<Item = T>,

source§

fn into_components(self) -> &'a mut [T]

source§

impl<T, C> IntoComponents<Box<[T]>> for Box<[C]>
where C: ArrayCast, <C as ArrayCast>::Array: ArrayExt<Item = T>,

source§

impl<T, C> IntoComponents<Vec<T>> for Vec<C>
where C: ArrayCast, <C as ArrayCast>::Array: ArrayExt<Item = T>,

source§

impl<T, C, const N: usize, const M: usize> IntoComponents<[T; M]> for [C; N]
where C: ArrayCast, <C as ArrayCast>::Array: ArrayExt<Item = T>,

Implementors§