Trait nannou::color::ConvertInto[][src]

pub trait ConvertInto<T>: Into<T> {
    fn convert_into(self) -> T;
fn convert_unclamped_into(self) -> T;
fn try_convert_into(self) -> Result<T, OutOfBounds<T>>; }
Expand description

A trait for converting a color into another.

Required methods

Convert into T with values clamped to the color defined bounds

use palette::ConvertInto;
use palette::Limited;
use palette::{Srgb, Lch};


let rgb: Srgb = Lch::new(50.0, 100.0, -175.0).convert_into();
assert!(rgb.is_valid());

Convert into T. The resulting color might be invalid in its color space

use palette::ConvertInto;
use palette::Limited;
use palette::{Srgb, Lch};

let rgb: Srgb = Lch::new(50.0, 100.0, -175.0).convert_unclamped_into();
assert!(!rgb.is_valid());

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

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

Implementors