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::model::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::model::Colour;
let colour = Colour::DARK_TEAL;
assert_eq!(colour.tuple(), (17, 128, 106));Colours can also be directly compared for equivalence:
use serenity::model::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: u32Implementations§
Source§impl Colour
 
impl Colour
Sourcepub const fn new(value: u32) -> Colour
 
pub const fn new(value: u32) -> Colour
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::model::Colour;
let colour = Colour::new(6573123);
assert_eq!(colour.tuple(), (100, 76, 67));Sourcepub const fn from_rgb(red: u8, green: u8, blue: u8) -> Colour
 
pub const fn from_rgb(red: u8, green: u8, blue: u8) -> Colour
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::model::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::model::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));Sourcepub const fn r(self) -> u8
 
pub const fn r(self) -> u8
Returns the red RGB component of this Colour.
§Examples
use serenity::model::Colour;
assert_eq!(Colour::new(6573123).r(), 100);Sourcepub const fn g(self) -> u8
 
pub const fn g(self) -> u8
Returns the green RGB component of this Colour.
§Examples
use serenity::model::Colour;
assert_eq!(Colour::new(6573123).g(), 76);Sourcepub const fn b(self) -> u8
 
pub const fn b(self) -> u8
Returns the blue RGB component of this Colour.
§Examples
use serenity::model::Colour;
assert_eq!(Colour::new(6573123).b(), 67);Sourcepub fn hex(self) -> String
 
pub fn hex(self) -> String
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::model::Colour;
assert_eq!(Colour::new(6573123).hex(), "644C43");Source§impl Colour
 
impl Colour
Sourcepub const BLITZ_BLUE: Colour
 
pub const BLITZ_BLUE: Colour
Creates a new Colour, setting its RGB value to (111, 198, 226).
Sourcepub const DARK_GREEN: Colour
 
pub const DARK_GREEN: Colour
Creates a new Colour, setting its RGB value to (31, 139, 76).
Sourcepub const DARK_MAGENTA: Colour
 
pub const DARK_MAGENTA: Colour
Creates a new Colour, setting its RGB value to (173, 20, 87).
Sourcepub const DARK_ORANGE: Colour
 
pub const DARK_ORANGE: Colour
Creates a new Colour, setting its RGB value to (168, 67, 0).
Sourcepub const DARK_PURPLE: Colour
 
pub const DARK_PURPLE: Colour
Creates a new Colour, setting its RGB value to (113, 54, 138).
Sourcepub const DARKER_GREY: Colour
 
pub const DARKER_GREY: Colour
Creates a new Colour, setting its RGB value to (84, 110, 122).
Sourcepub const FABLED_PINK: Colour
 
pub const FABLED_PINK: Colour
Creates a new Colour, setting its RGB value to (250, 177, 237).
Sourcepub const FADED_PURPLE: Colour
 
pub const FADED_PURPLE: Colour
Creates a new Colour, setting its RGB value to (136, 130, 196).
Sourcepub const LIGHT_GREY: Colour
 
pub const LIGHT_GREY: Colour
Creates a new Colour, setting its RGB value to (151, 156, 159).
Sourcepub const LIGHTER_GREY: Colour
 
pub const LIGHTER_GREY: Colour
Creates a new Colour, setting its RGB value to (149, 165, 166).
Sourcepub const MEIBE_PINK: Colour
 
pub const MEIBE_PINK: Colour
Creates a new Colour, setting its RGB value to (230, 131, 151).
Sourcepub const ROHRKATZE_BLUE: Colour
 
pub const ROHRKATZE_BLUE: Colour
Creates a new Colour, setting its RGB value to (117, 150, 255).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Colour
 
impl<'de> Deserialize<'de> for Colour
Source§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>,
Source§impl Ord for Colour
 
impl Ord for Colour
Source§impl PartialOrd for Colour
 
impl PartialOrd for Colour
impl Copy for Colour
impl Eq for Colour
impl StructuralPartialEq for Colour
Auto Trait Implementations§
impl Freeze for Colour
impl RefUnwindSafe for Colour
impl Send for Colour
impl Sync for Colour
impl Unpin for Colour
impl UnwindSafe for Colour
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneDebuggableStorage for Twhere
    T: DebuggableStorage + Clone,
 
impl<T> CloneDebuggableStorage for Twhere
    T: DebuggableStorage + Clone,
fn clone_storage(&self) -> Box<dyn CloneDebuggableStorage>
Source§impl<T> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
Source§impl<T> CloneableStorage for T
 
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
Source§impl<Q, K> Comparable<K> for Q
 
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
 
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
 
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
 
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.