Trait palette::ConvertInto

source ·
pub trait ConvertInto<T>: Into<T> {
    // Required methods
    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§

source

fn convert_into(self) -> T

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());
source

fn convert_unclamped_into(self) -> T

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());
source

fn try_convert_into(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::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()
    },
};

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T, U> ConvertInto<U> for T
where U: ConvertFrom<T>,