Trait cosmic::cosmic_theme::palette::cast::ComponentsFrom

source ·
pub trait ComponentsFrom<C> {
    // Required method
    fn components_from(colors: C) -> Self;
}
Expand description

Trait for casting a collection of color components into 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::ComponentsFrom, 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!(<[_; 6]>::components_from(array), [64, 139, 10, 93, 18, 214]);
assert_eq!(<&[_]>::components_from(slice), [64, 139, 10, 93, 18, 214]);
assert_eq!(<&mut [_]>::components_from(slice_mut), [64, 139, 10, 93, 18, 214]);
assert_eq!(Vec::<_>::components_from(vec), vec![64, 139, 10, 93, 18, 214]);

Owning types can be cast as slices, too:

use palette::{cast::ComponentsFrom, 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!(<&[_]>::components_from(&array), [64, 139, 10, 93, 18, 214]);
assert_eq!(<&mut [_]>::components_from(&mut vec), [64, 139, 10, 93, 18, 214]);

Required Methods§

source

fn components_from(colors: C) -> Self

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

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T, C> ComponentsFrom<C> for T
where C: IntoComponents<T>,