Trait cosmic::cosmic_theme::palette::convert::TryIntoColor

source ·
pub trait TryIntoColor<T>: Sized {
    // Required method
    fn try_into_color(self) -> Result<T, OutOfBounds<T>>;
}
Expand description

A trait for fallible conversion of a color into another.

U: TryIntoColor<T> is implemented for every type T: TryFromColor<U>.

See TryFromColor for more details.

Required Methods§

source

fn try_into_color(self) -> Result<T, OutOfBounds<T>>

Convert into 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::TryIntoColor;
 use palette::{Hsl, Srgb};

 let rgb: Srgb = match Hsl::new(150.0, 1.0, 1.1).try_into_color() {
     Ok(color) => color,
     Err(err) => {
         println!("Color is out of bounds");
         err.color()
     }
 };

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T, U> TryIntoColor<U> for T
where U: TryFromColor<T>,