Struct serenity::utils::Colour
[−]
[src]
pub struct Colour(pub u32);
A utility struct to help with working with the basic representation of a
colour. This is particularly useful when working with a Role
's colour,
as the API works with an integer value instead of an RGB value.
Instances can be created by using the struct's associated functions. These produce presets equivalent to those found in the official client's colour picker.
Examples
Passing in a role's colour, and then retrieving its green component
via g
:
use serenity::utils::Colour; // assuming a `role` has already been bound let green = role.colour.g(); println!("The green component is: {}", green);
Creating an instance with the dark_teal
presets:
use serenity::utils::Colour; let colour = Colour::dark_teal(); assert_eq!(colour.tuple(), (17, 128, 106));
Colours can also be directly compared for equivalence:
use serenity::utils::Colour; let blitz_blue = Colour::blitz_blue(); let fooyoo = Colour::fooyoo(); let fooyoo2 = Colour::fooyoo(); assert!(blitz_blue != fooyoo); assert_eq!(fooyoo, fooyoo2); assert!(blitz_blue > fooyoo);
Methods
impl Colour
[src]
fn new(value: u32) -> Colour
[src]
Generates a new Colour with the given integer value set.
Examples
Create a new Colour, and then ensure that its inner value is equivalent
to a specific RGB value, retrieved via tuple
:
use serenity::utils::Colour; let colour = Colour::new(6573123); assert_eq!(colour.tuple(), (100, 76, 67));
fn from_rgb(r: u8, g: u8, b: u8) -> Colour
[src]
Generates a new Colour from an RGB value, creating an inner u32 representation.
Examples
Creating a Colour
via its RGB values will set its inner u32 correctly:
use serenity::utils::Colour; assert!(Colour::from_rgb(255, 0, 0).0 == 0xFF0000); assert!(Colour::from_rgb(217, 23, 211).0 == 0xD917D3);
And you can then retrieve those same RGB values via its methods:
use serenity::utils::Colour; let colour = Colour::from_rgb(217, 45, 215); assert_eq!(colour.r(), 217); assert_eq!(colour.g(), 45); assert_eq!(colour.b(), 215); assert_eq!(colour.tuple(), (217, 45, 215));
fn r(&self) -> u8
[src]
Returns the red RGB component of this Colour.
Examples
use serenity::utils::Colour; assert_eq!(Colour::new(6573123).r(), 100);
fn g(&self) -> u8
[src]
Returns the green RGB component of this Colour.
Examples
use serenity::utils::Colour; assert_eq!(Colour::new(6573123).g(), 76);
fn b(&self) -> u8
[src]
Returns the blue RGB component of this Colour.
Examples
use serenity::utils::Colour; assert_eq!(Colour::new(6573123).b(), 67);
fn tuple(&self) -> (u8, u8, u8)
[src]
impl Colour
[src]
fn blitz_blue() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (111, 198, 226)
.
fn blue() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (52, 152, 219)
.
fn blurple() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (114, 137, 218)
.
fn dark_blue() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (32, 102, 148)
.
fn dark_gold() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (194, 124, 14)
.
fn dark_green() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (31, 139, 76)
.
fn dark_grey() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (96, 125, 139)
.
fn dark_magenta() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (173, 20, 87)
.
fn dark_orange() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (168, 67, 0)
.
fn dark_purple() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (113, 54, 138)
.
fn dark_red() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (153, 45, 34)
.
fn dark_teal() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (17, 128, 106)
.
fn darker_grey() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (84, 110, 122)
.
fn fabled_pink() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (250, 177, 237)
.
fn faded_purple() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (136, 130, 196)
.`
fn fooyoo() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (17, 202, 128)
.
fn gold() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (241, 196, 15)
.
fn kerbal() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (186, 218, 85)
.
fn light_grey() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (151, 156, 159)
.
fn lighter_grey() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (149, 165, 166)
.
fn magenta() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (233, 30, 99)
.
fn meibe_pink() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (230, 131, 151)
.
fn orange() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (230, 126, 34)
.
fn purple() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (155, 89, 182)
.
fn red() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (231, 76, 60)
.
fn rohrkatze_blue() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (117, 150, 255)
.
fn rosewater() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (246, 219, 216)
.
fn teal() -> Colour
[src]
Creates a new Colour
, setting its RGB value to (26, 188, 156)
.
Trait Implementations
impl Clone for Colour
[src]
fn clone(&self) -> Colour
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Copy for Colour
[src]
impl Debug for Colour
[src]
impl Eq for Colour
[src]
impl Ord for Colour
[src]
fn cmp(&self, __arg_0: &Colour) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.22.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.22.0[src]
Compares and returns the minimum of two values. Read more
impl PartialEq for Colour
[src]
fn eq(&self, __arg_0: &Colour) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Colour) -> bool
[src]
This method tests for !=
.
impl PartialOrd for Colour
[src]
fn partial_cmp(&self, __arg_0: &Colour) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &Colour) -> bool
[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &Colour) -> bool
[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &Colour) -> bool
[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &Colour) -> bool
[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl From<i32> for Colour
[src]
fn from(value: i32) -> Colour
[src]
Constructs a Colour from a i32.
This is used for functions that accept Into<Colour>
.
This is useful when providing hex values.
Examples
use serenity::utils::Colour; assert_eq!(Colour::from(0xDEA584).tuple(), (222, 165, 132));
impl From<u32> for Colour
[src]
fn from(value: u32) -> Colour
[src]
Constructs a Colour from a u32.
This is used for functions that accept Into<Colour>
.
Examples
use serenity::utils::Colour; assert_eq!(Colour::from(6573123u32).r(), 100);
impl From<u64> for Colour
[src]
fn from(value: u64) -> Colour
[src]
Constructs a Colour from a u32.
This is used for functions that accept Into<Colour>
.
Examples
use serenity::utils::Colour; assert_eq!(Colour::from(6573123u64).r(), 100);