Trait cosmic::cosmic_theme::palette::IntoColorMut
source · pub trait IntoColorMut<T>: FromColorMut<T>where
T: FromColorMut<Self> + ?Sized,{
// Required method
fn into_color_mut(&mut self) -> FromColorMutGuard<'_, T, Self>;
}
Expand description
Temporarily convert colors in place. The Into
counterpart to
FromColorMut
.
See FromColorMut
for more details and examples.
use palette::{IntoColorMut, ShiftHueAssign, Srgb, Hsv};
let mut rgb = [
Srgb::new(1.0, 0.0, 0.0),
Srgb::new(0.0, 1.0, 0.0),
Srgb::new(0.0, 0.0, 1.0),
];
{
let hsv: &mut [Hsv] = &mut rgb.into_color_mut(); // The guard is coerced into a slice.
// All of the colors in `rgb` have been converted to `Hsv`:
assert_eq!(
hsv,
[
Hsv::new(0.0, 1.0, 1.0),
Hsv::new(120.0, 1.0, 1.0),
Hsv::new(240.0, 1.0, 1.0),
]
);
hsv.shift_hue_assign(60.0);
} // The guard is dropped here and the colors are restored to `Srgb`.
// Notice how the colors in `rgb` have changed:
assert_eq!(
rgb,
[
Srgb::new(1.0, 1.0, 0.0),
Srgb::new(0.0, 1.0, 1.0),
Srgb::new(1.0, 0.0, 1.0),
]
);
Required Methods§
sourcefn into_color_mut(&mut self) -> FromColorMutGuard<'_, T, Self>
fn into_color_mut(&mut self) -> FromColorMutGuard<'_, T, Self>
Temporarily convert to another color type in place.
This reuses the memory space, and the returned scope guard will restore the converted colors to their original type when it’s dropped.
Object Safety§
This trait is not object safe.