Struct 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]);

Trait Implementations§

Source§

impl Add<u8> for Color

Source§

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

Source§

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 duplicate 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].

Source§

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>,

Source§

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>,

Source§

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

Source§

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>,

Source§

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>,

Source§

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

Source§

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>,

Source§

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

Source§

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

Source§

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>,

Source§

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>,

Source§

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

Source§

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>,

Source§

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

Source§

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]);
Source§

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

Source§

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. Read more
Source§

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

Source§

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>,

Source§

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

Source§

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>,

Source§

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>,

Source§

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

Source§

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>,

Source§

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

Source§

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

Source§

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>,

Source§

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>,

Source§

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

Source§

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>,

Source§

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

Source§

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>,

Source§

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>,

Source§

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

Source§

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>,

Source§

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>,

Source§

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

Source§

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>,

Source§

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

Source§

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

Source§

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>,

Source§

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>,

Source§

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

Source§

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>,

Source§

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

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Source§

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

Source§

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.

Source§

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. Read more
Source§

impl Copy for Color

Source§

impl Eq for Color

Auto Trait Implementations§

§

impl Freeze for Color

§

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
Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

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

Source§

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

Compare self to key and return true if they are equal.
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

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§

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>,

Source§

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>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

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