Trait palette::convert::FromColor[][src]

pub trait FromColor<T>: Sized {
    fn from_color(t: T) -> Self;
}

A trait for converting one color from another, in a possibly lossy way.

U: FromColor<T> is implemented for every type U: FromColorUnclamped<T> + Clamp.

See FromColorUnclamped for a lossless version of this trait. See TryFromColor for a trait that gives an error when the result is out of bounds.

The Difference Between FromColor and From

The conversion traits, including FromColor, were added to gain even more flexibility than what From and the other standard library traits can give. There are a few subtle, but important, differences in their semantics:

See the convert module for how to implement FromColorUnclamped for custom colors.

Required methods

fn from_color(t: T) -> Self[src]

Convert from T with values clamped to the color defined bounds.

use palette::{Clamp, FromColor, Lch, Srgb};

let rgb = Srgb::from_color(Lch::new(50.0, 100.0, -175.0));
assert!(rgb.is_within_bounds());
Loading content...

Implementors

impl<T, U> FromColor<T> for U where
    U: FromColorUnclamped<T> + Clamp
[src]

Loading content...