[−][src]Struct serenity::utils::Colour
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
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);
Methods
impl Colour
[src]
impl Colour
pub fn new(value: u32) -> Colour
[src]
pub 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 tuple
:
use serenity::utils::Colour; let colour = Colour::new(6573123); assert_eq!(colour.tuple(), (100, 76, 67));
pub fn from_rgb(red: u8, green: u8, blue: u8) -> Colour
[src]
pub 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));
pub fn r(&self) -> u8
[src]
pub fn r(&self) -> u8
Returns the red RGB component of this Colour.
Examples
use serenity::utils::Colour; assert_eq!(Colour::new(6573123).r(), 100);
pub fn g(&self) -> u8
[src]
pub fn g(&self) -> u8
Returns the green RGB component of this Colour.
Examples
use serenity::utils::Colour; assert_eq!(Colour::new(6573123).g(), 76);
pub fn b(&self) -> u8
[src]
pub fn b(&self) -> u8
Returns the blue RGB component of this Colour.
Examples
use serenity::utils::Colour; assert_eq!(Colour::new(6573123).b(), 67);
pub fn tuple(&self) -> (u8, u8, u8)
[src]
pub 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
r
, g
, and b
.
Examples
use serenity::utils::Colour; assert_eq!(Colour::new(6573123).tuple(), (100, 76, 67));
pub fn hex(&self) -> String
[src]
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");
impl Colour
[src]
impl Colour
pub const BLITZ_BLUE: Colour
[src]
Creates a new Colour
, setting its RGB value to (111, 198, 226)
.
pub const BLUE: Colour
[src]
Creates a new Colour
, setting its RGB value to (52, 152, 219)
.
pub const BLURPLE: Colour
[src]
Creates a new Colour
, setting its RGB value to (114, 137, 218)
.
pub const DARK_BLUE: Colour
[src]
Creates a new Colour
, setting its RGB value to (32, 102, 148)
.
pub const DARK_GOLD: Colour
[src]
Creates a new Colour
, setting its RGB value to (194, 124, 14)
.
pub const DARK_GREEN: Colour
[src]
Creates a new Colour
, setting its RGB value to (31, 139, 76)
.
pub const DARK_GREY: Colour
[src]
Creates a new Colour
, setting its RGB value to (96, 125, 139)
.
pub const DARK_MAGENTA: Colour
[src]
Creates a new Colour
, setting its RGB value to (173, 20, 87)
.
pub const DARK_ORANGE: Colour
[src]
Creates a new Colour
, setting its RGB value to (168, 67, 0)
.
pub const DARK_PURPLE: Colour
[src]
Creates a new Colour
, setting its RGB value to (113, 54, 138)
.
pub const DARK_RED: Colour
[src]
Creates a new Colour
, setting its RGB value to (153, 45, 34)
.
pub const DARK_TEAL: Colour
[src]
Creates a new Colour
, setting its RGB value to (17, 128, 106)
.
pub const DARKER_GREY: Colour
[src]
Creates a new Colour
, setting its RGB value to (84, 110, 122)
.
pub const FABLED_PINK: Colour
[src]
Creates a new Colour
, setting its RGB value to (250, 177, 237)
.
pub const FADED_PURPLE: Colour
[src]
Creates a new Colour
, setting its RGB value to (136, 130, 196)
.`
pub const FOOYOO: Colour
[src]
Creates a new Colour
, setting its RGB value to (17, 202, 128)
.
pub const GOLD: Colour
[src]
Creates a new Colour
, setting its RGB value to (241, 196, 15)
.
pub const KERBAL: Colour
[src]
Creates a new Colour
, setting its RGB value to (186, 218, 85)
.
pub const LIGHT_GREY: Colour
[src]
Creates a new Colour
, setting its RGB value to (151, 156, 159)
.
pub const LIGHTER_GREY: Colour
[src]
Creates a new Colour
, setting its RGB value to (149, 165, 166)
.
pub const MAGENTA: Colour
[src]
Creates a new Colour
, setting its RGB value to (233, 30, 99)
.
pub const MEIBE_PINK: Colour
[src]
Creates a new Colour
, setting its RGB value to (230, 131, 151)
.
pub const ORANGE: Colour
[src]
Creates a new Colour
, setting its RGB value to (230, 126, 34)
.
pub const PURPLE: Colour
[src]
Creates a new Colour
, setting its RGB value to (155, 89, 182)
.
pub const RED: Colour
[src]
Creates a new Colour
, setting its RGB value to (231, 76, 60)
.
pub const ROHRKATZE_BLUE: Colour
[src]
Creates a new Colour
, setting its RGB value to (117, 150, 255)
.
pub const ROSEWATER: Colour
[src]
Creates a new Colour
, setting its RGB value to (246, 219, 216)
.
pub const TEAL: Colour
[src]
Creates a new Colour
, setting its RGB value to (26, 188, 156)
.
pub fn blitz_blue() -> Colour
[src]
pub fn blitz_blue() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (111, 198, 226)
.
pub fn blue() -> Colour
[src]
pub fn blue() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (52, 152, 219)
.
pub fn blurple() -> Colour
[src]
pub fn blurple() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (114, 137, 218)
.
pub fn dark_blue() -> Colour
[src]
pub fn dark_blue() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (32, 102, 148)
.
pub fn dark_gold() -> Colour
[src]
pub fn dark_gold() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (194, 124, 14)
.
pub fn dark_green() -> Colour
[src]
pub fn dark_green() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (31, 139, 76)
.
pub fn dark_grey() -> Colour
[src]
pub fn dark_grey() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (96, 125, 139)
.
pub fn dark_magenta() -> Colour
[src]
pub fn dark_magenta() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (173, 20, 87)
.
pub fn dark_orange() -> Colour
[src]
pub fn dark_orange() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (168, 67, 0)
.
pub fn dark_purple() -> Colour
[src]
pub fn dark_purple() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (113, 54, 138)
.
pub fn dark_red() -> Colour
[src]
pub fn dark_red() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (153, 45, 34)
.
pub fn dark_teal() -> Colour
[src]
pub fn dark_teal() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (17, 128, 106)
.
pub fn darker_grey() -> Colour
[src]
pub fn darker_grey() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (84, 110, 122)
.
pub fn fabled_pink() -> Colour
[src]
pub fn fabled_pink() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (250, 177, 237)
.
pub fn faded_purple() -> Colour
[src]
pub fn faded_purple() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (136, 130, 196)
.`
pub fn fooyoo() -> Colour
[src]
pub fn fooyoo() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (17, 202, 128)
.
pub fn gold() -> Colour
[src]
pub fn gold() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (241, 196, 15)
.
pub fn kerbal() -> Colour
[src]
pub fn kerbal() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (186, 218, 85)
.
pub fn light_grey() -> Colour
[src]
pub fn light_grey() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (151, 156, 159)
.
pub fn lighter_grey() -> Colour
[src]
pub fn lighter_grey() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (149, 165, 166)
.
pub fn magenta() -> Colour
[src]
pub fn magenta() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (233, 30, 99)
.
pub fn meibe_pink() -> Colour
[src]
pub fn meibe_pink() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (230, 131, 151)
.
pub fn orange() -> Colour
[src]
pub fn orange() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (230, 126, 34)
.
pub fn purple() -> Colour
[src]
pub fn purple() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (155, 89, 182)
.
pub fn red() -> Colour
[src]
pub fn red() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (231, 76, 60)
.
pub fn rohrkatze_blue() -> Colour
[src]
pub fn rohrkatze_blue() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (117, 150, 255)
.
pub fn rosewater() -> Colour
[src]
pub fn rosewater() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (246, 219, 216)
.
pub fn teal() -> Colour
[src]
pub fn teal() -> Colour
: Use the constant instead
Creates a new Colour
, setting its RGB value to (26, 188, 156)
.
Trait Implementations
impl PartialOrd<Colour> for Colour
[src]
impl PartialOrd<Colour> for Colour
fn partial_cmp(&self, other: &Colour) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &Colour) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Colour) -> bool
[src]
fn lt(&self, other: &Colour) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Colour) -> bool
[src]
fn le(&self, other: &Colour) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Colour) -> bool
[src]
fn gt(&self, other: &Colour) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Colour) -> bool
[src]
fn ge(&self, other: &Colour) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Default for Colour
[src]
impl Default for Colour
impl Ord for Colour
[src]
impl Ord for Colour
fn cmp(&self, other: &Colour) -> Ordering
[src]
fn cmp(&self, other: &Colour) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl PartialEq<Colour> for Colour
[src]
impl PartialEq<Colour> for Colour
fn eq(&self, other: &Colour) -> bool
[src]
fn eq(&self, other: &Colour) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Colour) -> bool
[src]
fn ne(&self, other: &Colour) -> bool
This method tests for !=
.
impl From<i32> for Colour
[src]
impl From<i32> for Colour
fn from(value: i32) -> Colour
[src]
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::utils::Colour; assert_eq!(Colour::from(0xDEA584).tuple(), (222, 165, 132));
impl From<u32> for Colour
[src]
impl From<u32> for Colour
fn from(value: u32) -> Colour
[src]
fn from(value: u32) -> Colour
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]
impl From<u64> for Colour
fn from(value: u64) -> Colour
[src]
fn from(value: u64) -> Colour
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);
impl From<(u8, u8, u8)> for Colour
[src]
impl From<(u8, u8, u8)> for Colour
impl Clone for Colour
[src]
impl Clone for Colour
fn clone(&self) -> Colour
[src]
fn clone(&self) -> Colour
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Copy for Colour
[src]
impl Copy for Colour
impl Eq for Colour
[src]
impl Eq for Colour
impl Debug for Colour
[src]
impl Debug for Colour
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Serialize for Colour
[src]
impl Serialize for Colour
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<'de> Deserialize<'de> for Colour
[src]
impl<'de> Deserialize<'de> for Colour
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
type Owned = T
fn to_owned(&self) -> T
[src]
fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut T)
[src]
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
impl<T> Erased for T
impl<T> Erased for T
impl<T> Typeable for T where
T: Any,
impl<T> Typeable for T where
T: Any,
impl<T> DebugAny for T where
T: Any + Debug,
[src]
impl<T> DebugAny for T where
T: Any + Debug,
impl<T> CloneAny for T where
T: Clone + Any,
[src]
impl<T> CloneAny for T where
T: Clone + Any,
fn clone_any(&self) -> Box<dyn CloneAny + 'static>
[src]
fn clone_any(&self) -> Box<dyn CloneAny + 'static>
fn clone_any_send(&self) -> Box<dyn CloneAny + 'static + Send> where
T: Send,
[src]
fn clone_any_send(&self) -> Box<dyn CloneAny + 'static + Send> where
T: Send,
fn clone_any_sync(&self) -> Box<dyn CloneAny + 'static + Sync> where
T: Sync,
[src]
fn clone_any_sync(&self) -> Box<dyn CloneAny + 'static + Sync> where
T: Sync,
fn clone_any_send_sync(&self) -> Box<dyn CloneAny + 'static + Sync + Send> where
T: Send + Sync,
[src]
fn clone_any_send_sync(&self) -> Box<dyn CloneAny + 'static + Sync + Send> where
T: Send + Sync,
impl<T> UnsafeAny for T where
T: Any,
impl<T> UnsafeAny for T where
T: Any,