Struct pix_engine::color::Color

source ·
pub struct Color { /* private fields */ }
Expand description

A color represented with a Mode.

Implementations§

source§

impl Color

source

pub const ALICE_BLUE: Self = _

source

pub const ANTIQUE_WHITE: Self = _

source

pub const AQUA: Self = _

source

pub const AQUA_MARINE: Self = _

source

pub const AZURE: Self = _

source

pub const BEIGE: Self = _

source

pub const BISQUE: Self = _

source

pub const BLACK: Self = _

source

pub const BLANCHE_DALMOND: Self = _

source

pub const BLUE: Self = _

source

pub const BLUE_VIOLET: Self = _

source

pub const BROWN: Self = _

source

pub const BURLY_WOOD: Self = _

source

pub const CADET_BLUE: Self = _

source

pub const CHARTREUSE: Self = _

source

pub const CHOCOLATE: Self = _

source

pub const CORAL: Self = _

source

pub const CORNFLOWER_BLUE: Self = _

source

pub const CORN_SILK: Self = _

source

pub const CRIMSON: Self = _

source

pub const CYAN: Self = _

source

pub const DARK_BLUE: Self = _

source

pub const DARK_CYAN: Self = _

source

pub const DARK_GOLDENROD: Self = _

source

pub const DARK_GRAY: Self = _

source

pub const DARK_GREEN: Self = _

source

pub const DARK_GREY: Self = _

source

pub const DARK_KHAKI: Self = _

source

pub const DARK_MAGENTA: Self = _

source

pub const DARK_OLIVE_GREEN: Self = _

source

pub const DARK_ORANGE: Self = _

source

pub const DARK_ORCHID: Self = _

source

pub const DARK_RED: Self = _

source

pub const DARK_SALMON: Self = _

source

pub const DARK_SEA_GREEN: Self = _

source

pub const DARK_SLATE_BLUE: Self = _

source

pub const DARK_SLATE_GRAY: Self = _

source

pub const DARK_SLATE_GREY: Self = _

source

pub const DARK_TURQUOISE: Self = _

source

pub const DARK_VIOLET: Self = _

source

pub const DEEP_PINK: Self = _

source

pub const DEEP_SKY_BLUE: Self = _

source

pub const DIM_GRAY: Self = _

source

pub const DIM_GREY: Self = _

source

pub const DODGER_BLUE: Self = _

source

pub const FIRE_BRICK: Self = _

source

pub const FLORAL_WHITE: Self = _

source

pub const FOREST_GREEN: Self = _

source

pub const FUCHSIA: Self = _

source

pub const GAINSBORO: Self = _

source

pub const GHOST_WHITE: Self = _

source

pub const GOLD: Self = _

source

pub const GOLDENROD: Self = _

source

pub const GRAY: Self = _

source

pub const GREEN: Self = _

source

pub const GREEN_YELLOW: Self = _

source

pub const GREY: Self = _

source

pub const HONEYDEW: Self = _

source

pub const HOTOINK: Self = _

source

pub const INDIAN_RED: Self = _

source

pub const INDIGO: Self = _

source

pub const IVORY: Self = _

source

pub const KHAKI: Self = _

source

pub const LAVENDER: Self = _

source

pub const LAVENDER_BLUSH: Self = _

source

pub const LAWN_GREEN: Self = _

source

pub const LEMON_CHIFFON: Self = _

source

pub const LIGHT_BLUE: Self = _

source

pub const LIGHT_CORAL: Self = _

source

pub const LIGHT_CYAN: Self = _

source

pub const LIGHT_GOLDENROD_YELLOW: Self = _

source

pub const LIGHT_GRAY: Self = _

source

pub const LIGHT_GREEN: Self = _

source

pub const LIGHT_GREY: Self = _

source

pub const LIGHT_PINK: Self = _

source

pub const LIGHT_SALMON: Self = _

source

pub const LIGHT_SEA_GREEN: Self = _

source

pub const LIGHT_SKY_BLUE: Self = _

source

pub const LIGHT_SLATE_GRAY: Self = _

source

pub const LIGHT_SLATE_GREY: Self = _

source

pub const LIGHT_STEEL_BLUE: Self = _

source

pub const LIGHT_YELLOW: Self = _

source

pub const LIME: Self = _

source

pub const LIME_GREEN: Self = _

source

pub const LINEN: Self = _

source

pub const MAGENTA: Self = _

source

pub const MAROON: Self = _

source

pub const MEDIUMAQUA_MARINE: Self = _

source

pub const MEDIUM_BLUE: Self = _

source

pub const MEDIUM_ORCHID: Self = _

source

pub const MEDIUM_PURPLE: Self = _

source

pub const MEDIUM_SEA_GREEN: Self = _

source

pub const MEDIUM_SLATE_BLUE: Self = _

source

pub const MEDIUM_SPRING_GREEN: Self = _

source

pub const MEDIUM_TURQUOISE: Self = _

source

pub const MEDIUM_VIOLET_RED: Self = _

source

pub const MIDNIGHT_BLUE: Self = _

source

pub const MINT_CREAM: Self = _

source

pub const MISTY_ROSE: Self = _

source

pub const MOCCASIN: Self = _

source

pub const NAVAJO_WHITE: Self = _

source

pub const NAVY: Self = _

source

pub const OLD_LACE: Self = _

source

pub const OLIVE: Self = _

source

pub const OLIVE_DRAB: Self = _

source

pub const ORANGE: Self = _

source

pub const ORANGE_RED: Self = _

source

pub const ORCHID: Self = _

source

pub const PALE_GOLDENROD: Self = _

source

pub const PALE_GREEN: Self = _

source

pub const PALE_TURQUOISE: Self = _

source

pub const PALE_VIOLET_RED: Self = _

source

pub const PAPAYA_WHIP: Self = _

source

pub const PEACH_PUFF: Self = _

source

pub const PERU: Self = _

source

pub const PINK: Self = _

source

pub const PLUM: Self = _

source

pub const POWDER_BLUE: Self = _

source

pub const PURPLE: Self = _

source

pub const REBECCA_PURPLE: Self = _

source

pub const RED: Self = _

source

pub const ROSY_BROWN: Self = _

source

pub const ROYAL_BLUE: Self = _

source

pub const SADDLE_BROWN: Self = _

source

pub const SALMON: Self = _

source

pub const SANDY_BROWN: Self = _

source

pub const SEA_GREEN: Self = _

source

pub const SEA_SHELL: Self = _

source

pub const SIENNA: Self = _

source

pub const SILVER: Self = _

source

pub const SKY_BLUE: Self = _

source

pub const SLATE_BLUE: Self = _

source

pub const SLATE_GRAY: Self = _

source

pub const SLATE_GREY: Self = _

source

pub const SNOW: Self = _

source

pub const SPRING_GREEN: Self = _

source

pub const STEEL_BLUE: Self = _

source

pub const TAN: Self = _

source

pub const TEAL: Self = _

source

pub const THISTLE: Self = _

source

pub const TOMATO: Self = _

source

pub const TRANSPARENT: Self = _

source

pub const TURQUOISE: Self = _

source

pub const VIOLET: Self = _

source

pub const WHEAT: Self = _

source

pub const WHITE: Self = _

source

pub const WHITE_SMOKE: Self = _

source

pub const YELLOW: Self = _

source

pub const YELLOW_GREEN: Self = _

source§

impl Color

source

pub fn from_slice<T, S>(mode: ColorMode, slice: S) -> PixResult<Self>
where T: Copy + Into<f64>, S: AsRef<[T]>,

Constructs a Color from a slice of 1-4 values. The number of values provided alter how they are interpreted similar to the color!, rgb!, hsb!, and hsl! macros.

Errors

If the slice is empty or has more than 4 values, an error is returned.

Examples
let vals: Vec<f64> = vec![128.0, 64.0, 0.0];
let c = Color::from_slice(ColorMode::Rgb, &vals)?; // RGB Vec
assert_eq!(c.channels(), [128, 64, 0, 255]);

let vals: [f64; 4] = [128.0, 64.0, 0.0, 128.0];
let c = Color::from_slice(ColorMode::Rgb, &vals[..])?; // RGBA slice
assert_eq!(c.channels(), [128, 64, 0, 128]);
source

pub const fn from_hex(hex: u32) -> Self

Constructs a Color from a u32 RGB hexadecimal value with max alpha.

Examples
let c = Color::from_hex(0xF0FF00);
assert_eq!(c.channels(), [240, 255, 0, 255]);
source

pub const fn from_hex_alpha(hex: u32) -> Self

Constructs a Color from a u32 RGBA hexadecimal value.

Examples
let c = Color::from_hex_alpha(0xF0FF_00FF);
assert_eq!(c.channels(), [240, 255, 0, 255]);

let c = Color::from_hex_alpha(0xF0FF_0080);
assert_eq!(c.channels(), [240, 255, 0, 128]);
source

pub const fn inverted(&self) -> Self

Constructs a Color by inverting the RGBA values.

Example
let c = Color::from_hex(0xF0FF00);
assert_eq!(c.inverted().as_hex(), 0x0F00FF);
source

pub fn blended<A>(&self, bg: Color, alpha: A) -> Self
where A: Into<f64>,

Constructs an opaque Color blended over a given background, using an alpha value.

source

pub fn lerp<A>(&self, other: Color, amt: A) -> Self
where A: Into<f64>,

Constructs a Color by linear interpolating between two Colors by a given amount between 0.0 and 1.0.

Examples
let from = rgb!(255, 0, 0);
let to = rgb!(0, 100, 255);
let lerped = from.lerp(to, 0.5);
assert_eq!(lerped.channels(), [128, 50, 128, 255]);

let from = rgb!(255, 0, 0);
let to = hsb!(120.0, 80.0, 100.0, 0.5);
let lerped = from.lerp(to, 0.25); // `to` is implicity converted to RGB
assert_eq!(lerped.channels(), [204, 64, 13, 223]);
source§

impl Color

source

pub const fn new(r: u8, g: u8, b: u8) -> Self

Constructs a Color with red, green, blue and max alpha.

Example
let c = Color::new(0, 0, 128);
assert_eq!(c.channels(), [0, 0, 128, 255]);
source

pub const fn new_alpha(r: u8, g: u8, b: u8, a: u8) -> Self

Constructs a Color with red, green, blue and alpha.

Example
let c = Color::new_alpha(0, 0, 128, 50);
assert_eq!(c.channels(), [0, 0, 128, 50]);
source

pub fn with_mode<T: Into<f64>>(mode: Mode, v1: T, v2: T, v3: T) -> Self

Constructs a Color with the given Mode and max alpha.

Examples
let c = Color::with_mode(ColorMode::Rgb, 0, 0, 128);
assert_eq!(c.channels(), [0, 0, 128, 255]);

let c = Color::with_mode(ColorMode::Hsb, 126.0, 50.0, 100.0);
assert_eq!(c.channels(), [128, 255, 140, 255]);
source

pub fn with_mode_alpha<T: Into<f64>>( mode: Mode, v1: T, v2: T, v3: T, alpha: T ) -> Self

Constructs a Color with the given Mode and alpha.

Examples
let c = Color::with_mode_alpha(ColorMode::Rgb, 0.0, 0.0, 128.0, 50.0);
assert_eq!(c.channels(), [0, 0, 128, 50]);

let c = Color::with_mode_alpha(ColorMode::Hsb, 126.0, 50.0, 100.0, 0.8);
assert_eq!(c.channels(), [128, 255, 140, 204]);
source

pub const fn rgb(r: u8, g: u8, b: u8) -> Self

Constructs a Color with red, green, blue and max alpha.

Alias for Color::new.

Example
let c = Color::rgb(128, 64, 0);
assert_eq!(c.channels(), [128, 64, 0, 255]);
source

pub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self

Constructs a Color with red, green, blue and alpha.

Alias for Color::new_alpha.

Example
let c = Color::rgba(128, 64, 128, 128);
assert_eq!(c.channels(), [128, 64, 128, 128]);
source

pub fn hsb<T: Into<f64>>(h: T, s: T, b: T) -> Self

Constructs a Color with hue, saturation, brightness and max alpha.

Example
let c = Color::hsb(126.0, 80.0, 50.0);
assert_eq!(c.channels(), [25, 128, 36, 255]);
source

pub fn hsba<T: Into<f64>>(h: T, s: T, b: T, a: T) -> Self

Constructs a Color with hue, saturation, brightness and alpha.

Example
let c = Color::hsba(126.0, 80.0, 50.0, 0.5);
assert_eq!(c.channels(), [25, 128, 36, 128]);
source

pub fn hsl<T: Into<f64>>(h: T, s: T, l: T) -> Self

Constructs a Color with hue, saturation, lightness and max alpha.

Example
let c = Color::hsl(126.0, 80.0, 50.0);
assert_eq!(c.channels(), [25, 230, 46, 255]);
source

pub fn hsla<T: Into<f64>>(h: T, s: T, l: T, a: T) -> Self

Constructs a Color with hue, saturation, lightness and alpha.

Example
let c = Color::hsla(126.0, 80.0, 50.0, 0.5);
assert_eq!(c.channels(), [25, 230, 46, 128]);
source

pub fn from_levels<T: Into<f64>>( mode: Mode, v1: T, v2: T, v3: T, alpha: T ) -> Self

Constructs a Color with the given Mode and alpha using levels ranging from 0.0..=1.0.

Example
let c = Color::from_levels(ColorMode::Rgb, 0.4, 0.5, 1.0, 0.8);
assert_eq!(c.channels(), [102, 128, 255, 204]);
source

pub fn random() -> Self

Constructs a random Color with red, green, blue and max alpha.

Example
let c = Color::random();
// `c.channels()` will return something like:
// [207, 12, 217, 255]
source

pub fn random_alpha() -> Self

Constructs a random Color with red, green, blue and alpha.

Example
let c = Color::random_alpha();
// `c.channels()` will return something like:
// [132, 159, 233, 76]
source

pub const fn as_hex(&self) -> u32

Returns the u32 RGB hexadecimal value of a Color.

Examples
let c = Color::rgb(240, 255, 0);
assert_eq!(c.as_hex(), 0xF0FF00);
source

pub const fn as_hex_alpha(&self) -> u32

Returns the u32 RGBA hexadecimal value of a Color.

Examples
let c = Color::rgb(240, 255, 0);
assert_eq!(c.as_hex_alpha(), 0xF0FF00FF);

let c = Color::rgba(240, 255, 0, 128);
assert_eq!(c.as_hex_alpha(), 0xF0FF0080);
source

pub const fn maxes(&self) -> [f64; 4]

Returns a list of max values for each color channel based on Mode.

Examples
let c = Color::rgb(0, 0, 0);
assert_eq!(c.maxes(), [255.0, 255.0, 255.0, 255.0]);

let c = Color::hsb(0.0, 0.0, 0.0);
assert_eq!(c.maxes(), [360.0, 100.0, 100.0, 1.0]);

let c = Color::hsl(0.0, 0.0, 0.0);
assert_eq!(c.maxes(), [360.0, 100.0, 100.0, 1.0]);
source

pub fn levels(&self) -> [f64; 4]

Returns the Color levels for the given Mode which range from 0.0..=1.0.

source

pub fn set_levels(&mut self, levels: [f64; 4])

Set the Color levels ranging from 0.0..=1.0 using the current Mode.

Example
let mut c = Color::rgba(128, 64, 128, 128);
c.set_levels([1.0, 0.5, 0.4, 1.0]);
assert_eq!(c.channels(), [255, 128, 102, 255]);
source

pub const fn channels(&self) -> [u8; 4]

Returns the Color channels as [red, green, blue, alpha] which range from 0..=255.

Example
let c = Color::rgba(128, 64, 128, 128);
assert_eq!(c.channels(), [128, 64, 128, 128]);
source

pub const fn mode(&self) -> Mode

Returns the current color Mode.

Examples
let c = Color::rgb(100, 0, 0);
assert_eq!(c.mode(), ColorMode::Rgb);

let c = Color::hsb(100.0, 0.0, 0.0);
assert_eq!(c.mode(), ColorMode::Hsb);
source

pub fn set_mode(&mut self, mode: Mode)

Set the color Mode.

Example
let mut c = Color::rgb(100, 0, 0);
c.set_mode(ColorMode::Hsb);
assert_eq!(c.mode(), ColorMode::Hsb);
source

pub const fn red(&self) -> u8

Returns the red Color channel ranging from 0..=255.

Example
let c = Color::rgb(100, 0, 0);
assert_eq!(c.red(), 100);
source

pub fn set_red(&mut self, r: u8)

Set the red Color channel ranging from 0..=255.

Example
let mut c = Color::default();
assert_eq!(c.channels(), [0, 0, 0, 255]);
c.set_red(100);
assert_eq!(c.channels(), [100, 0, 0, 255]);
source

pub const fn green(&self) -> u8

Returns the green Color channel ranging from 0..=255.

Example
let c = Color::rgb(0, 100, 0);
assert_eq!(c.green(), 100);
source

pub fn set_green(&mut self, g: u8)

Set the green Color channel ranging from 0..=255.

Example
let mut c = Color::default();
assert_eq!(c.channels(), [0, 0, 0, 255]);
c.set_green(100);
assert_eq!(c.channels(), [0, 100, 0, 255]);
source

pub const fn blue(&self) -> u8

Returns the blue Color channel ranging from 0..=255.

Example
let c = Color::rgb(0, 0, 100);
assert_eq!(c.blue(), 100);
source

pub fn set_blue(&mut self, b: u8)

Set the blue Color channel ranging from 0..=255.

Example
let mut c = Color::default();
assert_eq!(c.channels(), [0, 0, 0, 255]);
c.set_blue(100);
assert_eq!(c.channels(), [0, 0, 100, 255]);
source

pub const fn alpha(&self) -> u8

Returns the alpha Color channel ranging from 0..=255.

Examples
let c = Color::rgba(0, 0, 0, 100);
assert_eq!(c.alpha(), 100);
source

pub fn set_alpha(&mut self, a: u8)

Set the alpha Color channel ranging from 0..=255.

Examples
let mut c = Color::default();
assert_eq!(c.channels(), [0, 0, 0, 255]);
c.set_alpha(100);
assert_eq!(c.channels(), [0, 0, 0, 100]);
source

pub fn hue(&self) -> f64

Returns the hue ranging from 0.0..=360.0.

Example
let c = Color::rgb(0, 100, 0);
assert_eq!(c.hue(), 120.0);
source

pub fn set_hue<H: Into<f64>>(&mut self, h: H)

Set the hue ranging from 0.0..=360.0.

Example
let mut c = Color::rgb(128, 0, 0);
assert_eq!(c.channels(), [128, 0, 0, 255]);
c.set_hue(100.0);
assert_eq!(c.channels(), [43, 128, 0, 255]);
source

pub fn saturation(&self) -> f64

Returns the saturation ranging from 0.0..=100.0.

Example
let c = Color::rgb(0, 100, 0);
assert_eq!(c.saturation(), 100.0);
source

pub fn set_saturation<S: Into<f64>>(&mut self, s: S)

Set the saturation ranging from 0.0..=100.0. Defaults to Hsb if the current mode is not Hsb or Hsl already.

Examples
let mut c = Color::rgb(128, 0, 0);
assert_eq!(c.channels(), [128, 0, 0, 255]);
c.set_saturation(50.0);
assert_eq!(c.channels(), [128, 64, 64, 255]);

let mut c = Color::rgb(128, 0, 0);
c.set_mode(ColorMode::Hsl);
assert_eq!(c.channels(), [128, 0, 0, 255]);
c.set_saturation(50.0);
assert_eq!(c.channels(), [96, 32, 32, 255]);
source

pub fn brightness(&self) -> f64

Returns the brightness ranging from 0.0..=100.0.

Example
let c = Color::rgb(0, 102, 0);
assert_eq!(c.brightness(), 40.0);
source

pub fn set_brightness<B: Into<f64>>(&mut self, b: B)

Set the brightness ranging from 0.0..=100.0.

Example
let mut c = Color::rgb(128, 0, 0);
assert_eq!(c.channels(), [128, 0, 0, 255]);
c.set_brightness(90.0);
assert_eq!(c.channels(), [230, 0, 0, 255]);
source

pub fn lightness(&self) -> f64

Returns the lightness ranging from 0.0..=100.0.

Example
let c = Color::rgb(0, 102, 0);
assert_eq!(c.lightness(), 20.0);
source

pub fn set_lightness<L: Into<f64>>(&mut self, l: L)

Set the lightness ranging from 0.0..=100.0.

Example
let mut c = Color::rgb(128, 0, 0);
assert_eq!(c.channels(), [128, 0, 0, 255]);
c.set_lightness(90.0);
assert_eq!(c.channels(), [255, 204, 204, 255]);
source

pub fn to_vec(self) -> Vec<u8>

Returns Color as a Vec of [red, green, blue, alpha].

Example
let c = color!(100, 200, 50);
assert_eq!(c.to_vec(), vec![100, 200, 50, 255]);

Methods from Deref<Target = [u8; 4]>§

1.57.0 · source

pub fn as_slice(&self) -> &[T]

Returns a slice containing the entire array. Equivalent to &s[..].

source

pub fn each_ref(&self) -> [&T; N]

🔬This is a nightly-only experimental API. (array_methods)

Borrows each element and returns an array of references with the same size as self.

Example
#![feature(array_methods)]

let floats = [3.1, 2.7, -1.0];
let float_refs: [&f64; 3] = floats.each_ref();
assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);

This method is particularly useful if combined with other methods, like map. This way, you can avoid moving the original array if its elements are not Copy.

#![feature(array_methods)]

let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()];
let is_ascii = strings.each_ref().map(|s| s.is_ascii());
assert_eq!(is_ascii, [true, false, true]);

// We can still access the original array: it has not been moved.
assert_eq!(strings.len(), 3);
source

pub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])

🔬This is a nightly-only experimental API. (split_array)

Divides one array reference into two at an index.

The first will contain all indices from [0, M) (excluding the index M itself) and the second will contain all indices from [M, N) (excluding the index N itself).

Panics

Panics if M > N.

Examples
#![feature(split_array)]

let v = [1, 2, 3, 4, 5, 6];

{
   let (left, right) = v.split_array_ref::<0>();
   assert_eq!(left, &[]);
   assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}

{
    let (left, right) = v.split_array_ref::<2>();
    assert_eq!(left, &[1, 2]);
    assert_eq!(right, &[3, 4, 5, 6]);
}

{
    let (left, right) = v.split_array_ref::<6>();
    assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
    assert_eq!(right, &[]);
}
source

pub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])

🔬This is a nightly-only experimental API. (split_array)

Divides one array reference into two at an index from the end.

The first will contain all indices from [0, N - M) (excluding the index N - M itself) and the second will contain all indices from [N - M, N) (excluding the index N itself).

Panics

Panics if M > N.

Examples
#![feature(split_array)]

let v = [1, 2, 3, 4, 5, 6];

{
   let (left, right) = v.rsplit_array_ref::<0>();
   assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
   assert_eq!(right, &[]);
}

{
    let (left, right) = v.rsplit_array_ref::<2>();
    assert_eq!(left, &[1, 2, 3, 4]);
    assert_eq!(right, &[5, 6]);
}

{
    let (left, right) = v.rsplit_array_ref::<6>();
    assert_eq!(left, &[]);
    assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
source

pub fn as_ascii(&self) -> Option<&[AsciiChar; N]>

🔬This is a nightly-only experimental API. (ascii_char)

Converts this array of bytes into a array of ASCII characters, or returns None if any of the characters is non-ASCII.

Examples
#![feature(ascii_char)]
#![feature(const_option)]

const HEX_DIGITS: [std::ascii::Char; 16] =
    *b"0123456789abcdef".as_ascii().unwrap();

assert_eq!(HEX_DIGITS[1].as_str(), "1");
assert_eq!(HEX_DIGITS[10].as_str(), "a");
source

pub unsafe fn as_ascii_unchecked(&self) -> &[AsciiChar; N]

🔬This is a nightly-only experimental API. (ascii_char)

Converts this array of bytes into a array of ASCII characters, without checking whether they’re valid.

Safety

Every byte in the array must be in 0..=127, or else this is UB.

Trait Implementations§

source§

impl Add<u8> for Color

§

type Output = Color

The resulting type after applying the + operator.
source§

fn add(self, val: u8) -> Self::Output

Performs the + operation. Read more
source§

impl Add for Color

§

type Output = Color

The resulting type after applying the + operator.
source§

fn add(self, other: Color) -> Self::Output

Performs the + operation. Read more
source§

impl AddAssign<u8> for Color

source§

fn add_assign(&mut self, val: u8)

Performs the += operation. Read more
source§

impl AddAssign for Color

source§

fn add_assign(&mut self, other: Color)

Performs the += operation. Read more
source§

impl Clone for Color

source§

fn clone(&self) -> Color

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Color

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Color

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Deref for Color

source§

fn deref(&self) -> &Self::Target

Deref Color to &[u8; 4].

§

type Target = [u8; 4]

The resulting type after dereferencing.
source§

impl<'de> Deserialize<'de> for Color

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Color

Display Color as “[r, g, b, a]”.

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Div<f32> for Color
where f32: Into<f64>,

§

type Output = Color

The resulting type after applying the / operator.
source§

fn div(self, s: f32) -> Self::Output

Performs the / operation. Read more
source§

impl Div<f64> for Color
where f64: Into<f64>,

§

type Output = Color

The resulting type after applying the / operator.
source§

fn div(self, s: f64) -> Self::Output

Performs the / operation. Read more
source§

impl Div<i128> for Color

§

type Output = Color

The resulting type after applying the / operator.
source§

fn div(self, s: i128) -> Self::Output

Performs the / operation. Read more
source§

impl Div<i16> for Color
where i16: Into<f64>,

§

type Output = Color

The resulting type after applying the / operator.
source§

fn div(self, s: i16) -> Self::Output

Performs the / operation. Read more
source§

impl Div<i32> for Color
where i32: Into<f64>,

§

type Output = Color

The resulting type after applying the / operator.
source§

fn div(self, s: i32) -> Self::Output

Performs the / operation. Read more
source§

impl Div<i64> for Color

§

type Output = Color

The resulting type after applying the / operator.
source§

fn div(self, s: i64) -> Self::Output

Performs the / operation. Read more
source§

impl Div<i8> for Color
where i8: Into<f64>,

§

type Output = Color

The resulting type after applying the / operator.
source§

fn div(self, s: i8) -> Self::Output

Performs the / operation. Read more
source§

impl Div<isize> for Color

§

type Output = Color

The resulting type after applying the / operator.
source§

fn div(self, s: isize) -> Self::Output

Performs the / operation. Read more
source§

impl Div<u128> for Color

§

type Output = Color

The resulting type after applying the / operator.
source§

fn div(self, s: u128) -> Self::Output

Performs the / operation. Read more
source§

impl Div<u16> for Color
where u16: Into<f64>,

§

type Output = Color

The resulting type after applying the / operator.
source§

fn div(self, s: u16) -> Self::Output

Performs the / operation. Read more
source§

impl Div<u32> for Color
where u32: Into<f64>,

§

type Output = Color

The resulting type after applying the / operator.
source§

fn div(self, s: u32) -> Self::Output

Performs the / operation. Read more
source§

impl Div<u64> for Color

§

type Output = Color

The resulting type after applying the / operator.
source§

fn div(self, s: u64) -> Self::Output

Performs the / operation. Read more
source§

impl Div<u8> for Color
where u8: Into<f64>,

§

type Output = Color

The resulting type after applying the / operator.
source§

fn div(self, s: u8) -> Self::Output

Performs the / operation. Read more
source§

impl Div<usize> for Color

§

type Output = Color

The resulting type after applying the / operator.
source§

fn div(self, s: usize) -> Self::Output

Performs the / operation. Read more
source§

impl DivAssign<f32> for Color
where f32: Into<f64>,

source§

fn div_assign(&mut self, s: f32)

Performs the /= operation. Read more
source§

impl DivAssign<f64> for Color
where f64: Into<f64>,

source§

fn div_assign(&mut self, s: f64)

Performs the /= operation. Read more
source§

impl DivAssign<i128> for Color

source§

fn div_assign(&mut self, s: i128)

Performs the /= operation. Read more
source§

impl DivAssign<i16> for Color
where i16: Into<f64>,

source§

fn div_assign(&mut self, s: i16)

Performs the /= operation. Read more
source§

impl DivAssign<i32> for Color
where i32: Into<f64>,

source§

fn div_assign(&mut self, s: i32)

Performs the /= operation. Read more
source§

impl DivAssign<i64> for Color

source§

fn div_assign(&mut self, s: i64)

Performs the /= operation. Read more
source§

impl DivAssign<i8> for Color
where i8: Into<f64>,

source§

fn div_assign(&mut self, s: i8)

Performs the /= operation. Read more
source§

impl DivAssign<isize> for Color

source§

fn div_assign(&mut self, s: isize)

Performs the /= operation. Read more
source§

impl DivAssign<u128> for Color

source§

fn div_assign(&mut self, s: u128)

Performs the /= operation. Read more
source§

impl DivAssign<u16> for Color
where u16: Into<f64>,

source§

fn div_assign(&mut self, s: u16)

Performs the /= operation. Read more
source§

impl DivAssign<u32> for Color
where u32: Into<f64>,

source§

fn div_assign(&mut self, s: u32)

Performs the /= operation. Read more
source§

impl DivAssign<u64> for Color

source§

fn div_assign(&mut self, s: u64)

Performs the /= operation. Read more
source§

impl DivAssign<u8> for Color
where u8: Into<f64>,

source§

fn div_assign(&mut self, s: u8)

Performs the /= operation. Read more
source§

impl DivAssign<usize> for Color

source§

fn div_assign(&mut self, s: usize)

Performs the /= operation. Read more
source§

impl From<[f32; 1]> for Color

source§

fn from([gray]: [f32; 1]) -> Self

Convert f32 to grayscale Color

source§

impl From<[f32; 2]> for Color

source§

fn from([gray, alpha]: [f32; 2]) -> Self

Convert [f32; 2] to grayscale Color with alpha

source§

impl From<[f32; 3]> for Color

source§

fn from([r, g, b]: [f32; 3]) -> Self

Convert [f32; 3] to Color with max alpha

source§

impl From<[f32; 4]> for Color

source§

fn from([r, g, b, a]: [f32; 4]) -> Self

Convert [f32; 4] to Color

source§

impl From<[f64; 1]> for Color

source§

fn from([gray]: [f64; 1]) -> Self

Convert f64 to grayscale Color

source§

impl From<[f64; 2]> for Color

source§

fn from([gray, alpha]: [f64; 2]) -> Self

Convert [f64; 2] to grayscale Color with alpha

source§

impl From<[f64; 3]> for Color

source§

fn from([r, g, b]: [f64; 3]) -> Self

Convert [f64; 3] to Color with max alpha

source§

impl From<[f64; 4]> for Color

source§

fn from([r, g, b, a]: [f64; 4]) -> Self

Convert [f64; 4] to Color

source§

impl From<[i16; 1]> for Color

source§

fn from([gray]: [i16; 1]) -> Self

Convert i16 to grayscale Color

source§

impl From<[i16; 2]> for Color

source§

fn from([gray, alpha]: [i16; 2]) -> Self

Convert [i16; 2] to grayscale Color with alpha

source§

impl From<[i16; 3]> for Color

source§

fn from([r, g, b]: [i16; 3]) -> Self

Convert [i16; 3] to Color with max alpha

source§

impl From<[i16; 4]> for Color

source§

fn from([r, g, b, a]: [i16; 4]) -> Self

Convert [i16; 4] to Color

source§

impl From<[i32; 1]> for Color

source§

fn from([gray]: [i32; 1]) -> Self

Convert i32 to grayscale Color

source§

impl From<[i32; 2]> for Color

source§

fn from([gray, alpha]: [i32; 2]) -> Self

Convert [i32; 2] to grayscale Color with alpha

source§

impl From<[i32; 3]> for Color

source§

fn from([r, g, b]: [i32; 3]) -> Self

Convert [i32; 3] to Color with max alpha

source§

impl From<[i32; 4]> for Color

source§

fn from([r, g, b, a]: [i32; 4]) -> Self

Convert [i32; 4] to Color

source§

impl From<[i8; 1]> for Color

source§

fn from([gray]: [i8; 1]) -> Self

Convert i8 to grayscale Color

source§

impl From<[i8; 2]> for Color

source§

fn from([gray, alpha]: [i8; 2]) -> Self

Convert [i8; 2] to grayscale Color with alpha

source§

impl From<[i8; 3]> for Color

source§

fn from([r, g, b]: [i8; 3]) -> Self

Convert [i8; 3] to Color with max alpha

source§

impl From<[i8; 4]> for Color

source§

fn from([r, g, b, a]: [i8; 4]) -> Self

Convert [i8; 4] to Color

source§

impl From<[u16; 1]> for Color

source§

fn from([gray]: [u16; 1]) -> Self

Convert u16 to grayscale Color

source§

impl From<[u16; 2]> for Color

source§

fn from([gray, alpha]: [u16; 2]) -> Self

Convert [u16; 2] to grayscale Color with alpha

source§

impl From<[u16; 3]> for Color

source§

fn from([r, g, b]: [u16; 3]) -> Self

Convert [u16; 3] to Color with max alpha

source§

impl From<[u16; 4]> for Color

source§

fn from([r, g, b, a]: [u16; 4]) -> Self

Convert [u16; 4] to Color

source§

impl From<[u32; 1]> for Color

source§

fn from([gray]: [u32; 1]) -> Self

Convert u32 to grayscale Color

source§

impl From<[u32; 2]> for Color

source§

fn from([gray, alpha]: [u32; 2]) -> Self

Convert [u32; 2] to grayscale Color with alpha

source§

impl From<[u32; 3]> for Color

source§

fn from([r, g, b]: [u32; 3]) -> Self

Convert [u32; 3] to Color with max alpha

source§

impl From<[u32; 4]> for Color

source§

fn from([r, g, b, a]: [u32; 4]) -> Self

Convert [u32; 4] to Color

source§

impl From<[u8; 1]> for Color

source§

fn from([gray]: [u8; 1]) -> Self

Convert u8 to grayscale Color

source§

impl From<[u8; 2]> for Color

source§

fn from([gray, alpha]: [u8; 2]) -> Self

Convert [u8; 2] to grayscale Color with alpha

source§

impl From<[u8; 3]> for Color

source§

fn from([r, g, b]: [u8; 3]) -> Self

Convert [u8; 3] to Color with max alpha

source§

impl From<[u8; 4]> for Color

source§

fn from([r, g, b, a]: [u8; 4]) -> Self

Convert [u8; 4] to Color

source§

impl From<f32> for Color

source§

fn from(gray: f32) -> Self

Convert f32 to grayscale Color

source§

impl From<f64> for Color

source§

fn from(gray: f64) -> Self

Convert f64 to grayscale Color

source§

impl From<i16> for Color

source§

fn from(gray: i16) -> Self

Convert i16 to grayscale Color

source§

impl From<i32> for Color

source§

fn from(gray: i32) -> Self

Convert i32 to grayscale Color

source§

impl From<i8> for Color

source§

fn from(gray: i8) -> Self

Convert i8 to grayscale Color

source§

impl From<u16> for Color

source§

fn from(gray: u16) -> Self

Convert u16 to grayscale Color

source§

impl From<u32> for Color

source§

fn from(gray: u32) -> Self

Convert u32 to grayscale Color

source§

impl From<u8> for Color

source§

fn from(gray: u8) -> Self

Convert u8 to grayscale Color

source§

impl FromStr for Color

source§

fn from_str(string: &str) -> Result<Self, Self::Err>

Converts to Color from a hexadecimal string.

Examples
use std::str::FromStr;

let c = Color::from_str("#F0F")?; // 3-digit Hex string
assert_eq!(c.channels(), [255, 0, 255, 255]);

let c = Color::from_str("#F0F5")?; // 4-digit Hex string
assert_eq![c.channels(), [255, 0, 255, 85]];

let c = Color::from_str("#F0F5BF")?; // 6-digit Hex string
assert_eq!(c.channels(), [240, 245, 191, 255]);

let c = Color::from_str("#F0F5BF5F")?; // 8-digit Hex string
assert_eq!(c.channels(), [240, 245, 191, 95]);
§

type Err = Error

The associated error which can be returned from parsing.
source§

impl Hash for Color

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Index<usize> for Color

§

type Output = u8

The returned type after indexing.
source§

fn index(&self, idx: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl LowerHex for Color

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl Mul<Color> for f32
where f32: Into<f64>,

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, c: Color) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Color> for f64
where f64: Into<f64>,

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, c: Color) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Color> for i128

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, c: Color) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Color> for i16
where i16: Into<f64>,

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, c: Color) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Color> for i32
where i32: Into<f64>,

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, c: Color) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Color> for i64

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, c: Color) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Color> for i8
where i8: Into<f64>,

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, c: Color) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Color> for isize

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, c: Color) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Color> for u128

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, c: Color) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Color> for u16
where u16: Into<f64>,

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, c: Color) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Color> for u32
where u32: Into<f64>,

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, c: Color) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Color> for u64

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, c: Color) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Color> for u8
where u8: Into<f64>,

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, c: Color) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Color> for usize

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, c: Color) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<f32> for Color
where f32: Into<f64>,

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, s: f32) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<f64> for Color
where f64: Into<f64>,

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, s: f64) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<i128> for Color

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, s: i128) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<i16> for Color
where i16: Into<f64>,

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, s: i16) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<i32> for Color
where i32: Into<f64>,

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, s: i32) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<i64> for Color

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, s: i64) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<i8> for Color
where i8: Into<f64>,

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, s: i8) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<isize> for Color

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, s: isize) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<u128> for Color

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, s: u128) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<u16> for Color
where u16: Into<f64>,

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, s: u16) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<u32> for Color
where u32: Into<f64>,

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, s: u32) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<u64> for Color

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, s: u64) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<u8> for Color
where u8: Into<f64>,

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, s: u8) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<usize> for Color

§

type Output = Color

The resulting type after applying the * operator.
source§

fn mul(self, s: usize) -> Self::Output

Performs the * operation. Read more
source§

impl MulAssign<f32> for Color
where f32: Into<f64>,

source§

fn mul_assign(&mut self, s: f32)

Performs the *= operation. Read more
source§

impl MulAssign<f64> for Color
where f64: Into<f64>,

source§

fn mul_assign(&mut self, s: f64)

Performs the *= operation. Read more
source§

impl MulAssign<i128> for Color

source§

fn mul_assign(&mut self, s: i128)

Performs the *= operation. Read more
source§

impl MulAssign<i16> for Color
where i16: Into<f64>,

source§

fn mul_assign(&mut self, s: i16)

Performs the *= operation. Read more
source§

impl MulAssign<i32> for Color
where i32: Into<f64>,

source§

fn mul_assign(&mut self, s: i32)

Performs the *= operation. Read more
source§

impl MulAssign<i64> for Color

source§

fn mul_assign(&mut self, s: i64)

Performs the *= operation. Read more
source§

impl MulAssign<i8> for Color
where i8: Into<f64>,

source§

fn mul_assign(&mut self, s: i8)

Performs the *= operation. Read more
source§

impl MulAssign<isize> for Color

source§

fn mul_assign(&mut self, s: isize)

Performs the *= operation. Read more
source§

impl MulAssign<u128> for Color

source§

fn mul_assign(&mut self, s: u128)

Performs the *= operation. Read more
source§

impl MulAssign<u16> for Color
where u16: Into<f64>,

source§

fn mul_assign(&mut self, s: u16)

Performs the *= operation. Read more
source§

impl MulAssign<u32> for Color
where u32: Into<f64>,

source§

fn mul_assign(&mut self, s: u32)

Performs the *= operation. Read more
source§

impl MulAssign<u64> for Color

source§

fn mul_assign(&mut self, s: u64)

Performs the *= operation. Read more
source§

impl MulAssign<u8> for Color
where u8: Into<f64>,

source§

fn mul_assign(&mut self, s: u8)

Performs the *= operation. Read more
source§

impl MulAssign<usize> for Color

source§

fn mul_assign(&mut self, s: usize)

Performs the *= operation. Read more
source§

impl PartialEq for Color

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Color

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Sub<u8> for Color

§

type Output = Color

The resulting type after applying the - operator.
source§

fn sub(self, val: u8) -> Self::Output

Performs the - operation. Read more
source§

impl Sub for Color

§

type Output = Color

The resulting type after applying the - operator.
source§

fn sub(self, other: Color) -> Self::Output

Performs the - operation. Read more
source§

impl SubAssign<u8> for Color

source§

fn sub_assign(&mut self, val: u8)

Performs the -= operation. Read more
source§

impl SubAssign for Color

source§

fn sub_assign(&mut self, other: Color)

Performs the -= operation. Read more
source§

impl TryFrom<&str> for Color

source§

fn try_from(s: &str) -> Result<Self, Self::Error>

Try to create a Color from a hexadecimal string.

§

type Error = Error

The type returned in the event of a conversion error.
source§

impl UpperHex for Color

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl Copy for Color

source§

impl Eq for Color

Auto Trait Implementations§

§

impl RefUnwindSafe for Color

§

impl Send for Color

§

impl Sync for Color

§

impl Unpin for Color

§

impl UnwindSafe for Color

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,