pub struct Colour(pub u32);
utils
only.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
sourceimpl 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::utils::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::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));
sourcepub const fn r(self) -> u8
pub const fn r(self) -> u8
Returns the red RGB component of this Colour.
Examples
use serenity::utils::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::utils::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::utils::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::utils::Colour;
assert_eq!(Colour::new(6573123).hex(), "644C43");
sourceimpl Colour
impl Colour
sourcepub const BLITZ_BLUE: Colour = Colour(0x6FC6E2)
pub const BLITZ_BLUE: Colour = Colour(0x6FC6E2)
Creates a new Colour
, setting its RGB value to (111, 198, 226)
.
sourcepub const BLUE: Colour = Colour(0x3498DB)
pub const BLUE: Colour = Colour(0x3498DB)
Creates a new Colour
, setting its RGB value to (52, 152, 219)
.
sourcepub const BLURPLE: Colour = Colour(0x7289DA)
pub const BLURPLE: Colour = Colour(0x7289DA)
Creates a new Colour
, setting its RGB value to (114, 137, 218)
.
sourcepub const DARK_BLUE: Colour = Colour(0x206694)
pub const DARK_BLUE: Colour = Colour(0x206694)
Creates a new Colour
, setting its RGB value to (32, 102, 148)
.
sourcepub const DARK_GOLD: Colour = Colour(0xC27C0E)
pub const DARK_GOLD: Colour = Colour(0xC27C0E)
Creates a new Colour
, setting its RGB value to (194, 124, 14)
.
sourcepub const DARK_GREEN: Colour = Colour(0x1F8B4C)
pub const DARK_GREEN: Colour = Colour(0x1F8B4C)
Creates a new Colour
, setting its RGB value to (31, 139, 76)
.
sourcepub const DARK_GREY: Colour = Colour(0x607D8B)
pub const DARK_GREY: Colour = Colour(0x607D8B)
Creates a new Colour
, setting its RGB value to (96, 125, 139)
.
sourcepub const DARK_MAGENTA: Colour = Colour(0xAD1457)
pub const DARK_MAGENTA: Colour = Colour(0xAD1457)
Creates a new Colour
, setting its RGB value to (173, 20, 87)
.
sourcepub const DARK_ORANGE: Colour = Colour(0xA84300)
pub const DARK_ORANGE: Colour = Colour(0xA84300)
Creates a new Colour
, setting its RGB value to (168, 67, 0)
.
sourcepub const DARK_PURPLE: Colour = Colour(0x71368A)
pub const DARK_PURPLE: Colour = Colour(0x71368A)
Creates a new Colour
, setting its RGB value to (113, 54, 138)
.
sourcepub const DARK_RED: Colour = Colour(0x992D22)
pub const DARK_RED: Colour = Colour(0x992D22)
Creates a new Colour
, setting its RGB value to (153, 45, 34)
.
sourcepub const DARK_TEAL: Colour = Colour(0x11806A)
pub const DARK_TEAL: Colour = Colour(0x11806A)
Creates a new Colour
, setting its RGB value to (17, 128, 106)
.
sourcepub const DARKER_GREY: Colour = Colour(0x546E7A)
pub const DARKER_GREY: Colour = Colour(0x546E7A)
Creates a new Colour
, setting its RGB value to (84, 110, 122)
.
sourcepub const FABLED_PINK: Colour = Colour(0xFAB1ED)
pub const FABLED_PINK: Colour = Colour(0xFAB1ED)
Creates a new Colour
, setting its RGB value to (250, 177, 237)
.
sourcepub const FADED_PURPLE: Colour = Colour(0x8882C4)
pub const FADED_PURPLE: Colour = Colour(0x8882C4)
Creates a new Colour
, setting its RGB value to (136, 130, 196)
.
sourcepub const FOOYOO: Colour = Colour(0x11CA80)
pub const FOOYOO: Colour = Colour(0x11CA80)
Creates a new Colour
, setting its RGB value to (17, 202, 128)
.
sourcepub const GOLD: Colour = Colour(0xF1C40F)
pub const GOLD: Colour = Colour(0xF1C40F)
Creates a new Colour
, setting its RGB value to (241, 196, 15)
.
sourcepub const KERBAL: Colour = Colour(0xBADA55)
pub const KERBAL: Colour = Colour(0xBADA55)
Creates a new Colour
, setting its RGB value to (186, 218, 85)
.
sourcepub const LIGHT_GREY: Colour = Colour(0x979C9F)
pub const LIGHT_GREY: Colour = Colour(0x979C9F)
Creates a new Colour
, setting its RGB value to (151, 156, 159)
.
sourcepub const LIGHTER_GREY: Colour = Colour(0x95A5A6)
pub const LIGHTER_GREY: Colour = Colour(0x95A5A6)
Creates a new Colour
, setting its RGB value to (149, 165, 166)
.
sourcepub const MAGENTA: Colour = Colour(0xE91E63)
pub const MAGENTA: Colour = Colour(0xE91E63)
Creates a new Colour
, setting its RGB value to (233, 30, 99)
.
sourcepub const MEIBE_PINK: Colour = Colour(0xE68397)
pub const MEIBE_PINK: Colour = Colour(0xE68397)
Creates a new Colour
, setting its RGB value to (230, 131, 151)
.
sourcepub const ORANGE: Colour = Colour(0xE67E22)
pub const ORANGE: Colour = Colour(0xE67E22)
Creates a new Colour
, setting its RGB value to (230, 126, 34)
.
sourcepub const PURPLE: Colour = Colour(0x9B59B6)
pub const PURPLE: Colour = Colour(0x9B59B6)
Creates a new Colour
, setting its RGB value to (155, 89, 182)
.
sourcepub const RED: Colour = Colour(0xE74C3C)
pub const RED: Colour = Colour(0xE74C3C)
Creates a new Colour
, setting its RGB value to (231, 76, 60)
.
sourcepub const ROHRKATZE_BLUE: Colour = Colour(0x7596FF)
pub const ROHRKATZE_BLUE: Colour = Colour(0x7596FF)
Creates a new Colour
, setting its RGB value to (117, 150, 255)
.
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Colour
impl<'de> Deserialize<'de> for Colour
sourcefn 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
sourceimpl Ord for Colour
impl Ord for Colour
sourceimpl PartialOrd<Colour> for Colour
impl PartialOrd<Colour> for Colour
sourcefn partial_cmp(&self, other: &Colour) -> Option<Ordering>
fn partial_cmp(&self, other: &Colour) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Copy for Colour
impl Eq for Colour
impl StructuralEq for Colour
impl StructuralPartialEq for Colour
Auto Trait Implementations
impl RefUnwindSafe for Colour
impl Send for Colour
impl Sync for Colour
impl Unpin for Colour
impl UnwindSafe for Colour
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more