pub trait IntoColorUnclampedMut<T>: FromColorUnclampedMut<T>where
T: FromColorUnclampedMut<Self> + ?Sized,{
// Required method
fn into_color_unclamped_mut(
&mut self,
) -> FromColorUnclampedMutGuard<'_, T, Self>;
}
Expand description
Temporarily convert colors in place. The Into
counterpart to
FromColorUnclampedMut
.
See FromColorUnclampedMut
for more details and examples.
use palette::{convert::IntoColorUnclampedMut, 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_unclamped_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_unclamped_mut(
&mut self,
) -> FromColorUnclampedMutGuard<'_, T, Self>
fn into_color_unclamped_mut( &mut self, ) -> FromColorUnclampedMutGuard<'_, T, Self>
Temporarily convert to another color type in place, without clamping.
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.