[][src]Module twitchchat::color

Color types associated with Twitch.

Both an RGB triplet and named Colors are provided.

RGB

Try to parse a RGB from a #RRGGBB or RRGGBB

let rgb: RGB = "#00FF19".parse().unwrap();
assert_eq!(rgb.red(), 0x00);
assert_eq!(rgb.green(), 0xFF);
assert_eq!(rgb.blue(), 0x19);

// or without the leading octothrope
let rgb: RGB = "00FF19".parse().unwrap();
assert_eq!(rgb.red(), 0x00);
assert_eq!(rgb.green(), 0xFF);
assert_eq!(rgb.blue(), 0x19);

Turning it back into a string

let input = "#00FF19";
let rgb: RGB = input.parse().unwrap();
assert_eq!(rgb.to_string(), input);

Color

Try to parse a Color from a named color

let input = "Blue Violet";
let color: Color = input.parse().unwrap();
assert_eq!(color.rgb, RGB(0x8A, 0x2B, 0xE2));
assert_eq!(color.kind, TwitchColor::BlueViolet);

Conversions

let input = "Blue Violet";
let color: Color = input.parse().unwrap();

// Color can be converted into an RGB
let rgb: RGB = color.into();

// RGB can be converted into a TwitchColor
let twitch_color: TwitchColor = rgb.into();

// TwitchColor can be converted into an RGB
let rgb: RGB = twitch_color.into();

Structs

Color

A twitch color paired with an RGB

RGB

A 24-bit RGB triplet

Enums

ParseError

An error returned when trying to parse a string as an RGB triplet

TwitchColor

Named Twitch colors

Functions

twitch_colors

A utility method that returns an array of TwitchColors mapped to its corresponding RGB