Struct serenity::utils::Colour [−][src]
pub struct Colour(pub u32);
Expand description
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 Self::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 Self::DARK_TEAL
preset:
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);
Tuple Fields
0: u32
Implementations
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 Self::tuple
:
use serenity::utils::Colour;
let colour = Colour::new(6573123);
assert_eq!(colour.tuple(), (100, 76, 67));
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));
Returns the red RGB component of this Colour.
Examples
use serenity::utils::Colour;
assert_eq!(Colour::new(6573123).r(), 100);
Returns the green RGB component of this Colour.
Examples
use serenity::utils::Colour;
assert_eq!(Colour::new(6573123).g(), 76);
Returns the blue RGB component of this Colour.
Examples
use serenity::utils::Colour;
assert_eq!(Colour::new(6573123).b(), 67);
Returns a hexadecimal string of this Colour.
This is equivalent to passing the integer value through
std::fmt::UpperHex
with 0 padding and 6 width.
Examples
use serenity::utils::Colour;
assert_eq!(Colour::new(6573123).hex(), "644C43");
Creates a new Colour
, setting its RGB value to (111, 198, 226)
.
Creates a new Colour
, setting its RGB value to (31, 139, 76)
.
Creates a new Colour
, setting its RGB value to (173, 20, 87)
.
Creates a new Colour
, setting its RGB value to (168, 67, 0)
.
Creates a new Colour
, setting its RGB value to (113, 54, 138)
.
Creates a new Colour
, setting its RGB value to (84, 110, 122)
.
Creates a new Colour
, setting its RGB value to (250, 177, 237)
.
Creates a new Colour
, setting its RGB value to (136, 130, 196)
.
Creates a new Colour
, setting its RGB value to (151, 156, 159)
.
Creates a new Colour
, setting its RGB value to (149, 165, 166)
.
Creates a new Colour
, setting its RGB value to (230, 131, 151)
.
Creates a new Colour
, setting its RGB value to (117, 150, 255)
.
Trait Implementations
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Colour
impl UnwindSafe for Colour
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more