Struct Colour

Source
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: u32

Implementations§

Source§

impl Colour

Source

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));
Source

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));
Source

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);
Source

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);
Source

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);
Source

pub const fn tuple(self) -> (u8, u8, u8)

Returns a tuple of the red, green, and blue components of this Colour.

This is equivalent to creating a tuple with the return values of Self::r, Self::g, and Self::b.

§Examples
use serenity::model::Colour;

assert_eq!(Colour::new(6573123).tuple(), (100, 76, 67));
Source

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

Source

pub const BLITZ_BLUE: Colour

Creates a new Colour, setting its RGB value to (111, 198, 226).

Source

pub const BLUE: Colour

Creates a new Colour, setting its RGB value to (52, 152, 219).

Source

pub const BLURPLE: Colour

Creates a new Colour, setting its RGB value to (114, 137, 218).

Source

pub const DARK_BLUE: Colour

Creates a new Colour, setting its RGB value to (32, 102, 148).

Source

pub const DARK_GOLD: Colour

Creates a new Colour, setting its RGB value to (194, 124, 14).

Source

pub const DARK_GREEN: Colour

Creates a new Colour, setting its RGB value to (31, 139, 76).

Source

pub const DARK_GREY: Colour

Creates a new Colour, setting its RGB value to (96, 125, 139).

Source

pub const DARK_MAGENTA: Colour

Creates a new Colour, setting its RGB value to (173, 20, 87).

Source

pub const DARK_ORANGE: Colour

Creates a new Colour, setting its RGB value to (168, 67, 0).

Source

pub const DARK_PURPLE: Colour

Creates a new Colour, setting its RGB value to (113, 54, 138).

Source

pub const DARK_RED: Colour

Creates a new Colour, setting its RGB value to (153, 45, 34).

Source

pub const DARK_TEAL: Colour

Creates a new Colour, setting its RGB value to (17, 128, 106).

Source

pub const DARKER_GREY: Colour

Creates a new Colour, setting its RGB value to (84, 110, 122).

Source

pub const FABLED_PINK: Colour

Creates a new Colour, setting its RGB value to (250, 177, 237).

Source

pub const FADED_PURPLE: Colour

Creates a new Colour, setting its RGB value to (136, 130, 196).

Source

pub const FOOYOO: Colour

Creates a new Colour, setting its RGB value to (17, 202, 128).

Source

pub const GOLD: Colour

Creates a new Colour, setting its RGB value to (241, 196, 15).

Source

pub const KERBAL: Colour

Creates a new Colour, setting its RGB value to (186, 218, 85).

Source

pub const LIGHT_GREY: Colour

Creates a new Colour, setting its RGB value to (151, 156, 159).

Source

pub const LIGHTER_GREY: Colour

Creates a new Colour, setting its RGB value to (149, 165, 166).

Source

pub const MAGENTA: Colour

Creates a new Colour, setting its RGB value to (233, 30, 99).

Source

pub const MEIBE_PINK: Colour

Creates a new Colour, setting its RGB value to (230, 131, 151).

Source

pub const ORANGE: Colour

Creates a new Colour, setting its RGB value to (230, 126, 34).

Source

pub const PURPLE: Colour

Creates a new Colour, setting its RGB value to (155, 89, 182).

Source

pub const RED: Colour

Creates a new Colour, setting its RGB value to (231, 76, 60).

Source

pub const ROHRKATZE_BLUE: Colour

Creates a new Colour, setting its RGB value to (117, 150, 255).

Source

pub const ROSEWATER: Colour

Creates a new Colour, setting its RGB value to (246, 219, 216).

Source

pub const TEAL: Colour

Creates a new Colour, setting its RGB value to (26, 188, 156).

Trait Implementations§

Source§

impl Clone for Colour

Source§

fn clone(&self) -> Colour

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Colour

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Colour

Source§

fn default() -> Colour

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Colour

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<(u8, u8, u8)> for Colour

Source§

fn from((red, green, blue): (u8, u8, u8)) -> Self

Constructs a Colour from RGB.

Source§

impl From<i32> for Colour

Source§

fn from(value: i32) -> Colour

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::model::Colour;

assert_eq!(Colour::from(0xDEA584).tuple(), (222, 165, 132));
Source§

impl From<u32> for Colour

Source§

fn from(value: u32) -> Colour

Constructs a Colour from a u32.

This is used for functions that accept Into<Colour>.

§Examples
use serenity::model::Colour;

assert_eq!(Colour::from(6573123u32).r(), 100);
Source§

impl From<u64> for Colour

Source§

fn from(value: u64) -> Colour

Constructs a Colour from a u32.

This is used for functions that accept Into<Colour>.

§Examples
use serenity::model::Colour;

assert_eq!(Colour::from(6573123u64).r(), 100);
Source§

impl Ord for Colour

Source§

fn cmp(&self, other: &Colour) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Colour

Source§

fn eq(&self, other: &Colour) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Colour

Source§

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 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Colour

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Colour

Source§

impl Eq for Colour

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneDebuggableStorage for T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> CloneableStorage for T
where T: Any + Send + Sync + Clone,

Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DebuggableStorage for T
where T: Any + Send + Sync + Debug,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T