pub trait TryFromColor<T>: Sized {
// Required method
fn try_from_color(t: T) -> Result<Self, OutOfBounds<Self>>;
}
Expand description
A trait for fallible conversion of one color from another.
U: TryFromColor<T>
is implemented for every type U: FromColorUnclamped<T> + Clamp
.
See FromColor
for a lossy version of this trait.
See FromColorUnclamped
for a lossless version.
See the convert
module for how to implement FromColorUnclamped
for
custom colors.
Required Methods§
sourcefn try_from_color(t: T) -> Result<Self, OutOfBounds<Self>>
fn try_from_color(t: T) -> Result<Self, OutOfBounds<Self>>
Convert from T, returning ok if the color is inside of its defined
range, otherwise an OutOfBounds
error is returned which contains
the unclamped color.
use palette::convert::TryFromColor;
use palette::{Hsl, Srgb};
let rgb = match Srgb::try_from_color(Hsl::new(150.0, 1.0, 1.1)) {
Ok(color) => color,
Err(err) => {
println!("Color is out of bounds");
err.color()
}
};
Object Safety§
This trait is not object safe.