[−][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);
Implementations
impl Colour
[src]
pub const fn new(value: u32) -> Colour
[src]
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 const fn from_rgb(red: u8, green: u8, blue: u8) -> Colour
[src]
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 const fn r(self) -> u8
[src]
Returns the red RGB component of this Colour.
Examples
use serenity::utils::Colour; assert_eq!(Colour::new(6573123).r(), 100);
pub const fn g(self) -> u8
[src]
Returns the green RGB component of this Colour.
Examples
use serenity::utils::Colour; assert_eq!(Colour::new(6573123).g(), 76);
pub const fn b(self) -> u8
[src]
Returns the blue RGB component of this Colour.
Examples
use serenity::utils::Colour; assert_eq!(Colour::new(6573123).b(), 67);
pub const fn tuple(self) -> (u8, u8, u8)
[src]
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]
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]
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)
.
Trait Implementations
impl Clone for Colour
[src]
impl Copy for Colour
[src]
impl Debug for Colour
[src]
impl Default for Colour
[src]
impl<'de> Deserialize<'de> for Colour
[src]
pub fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Eq for Colour
[src]
impl From<(u8, u8, u8)> for Colour
[src]
impl From<i32> for Colour
[src]
pub fn from(value: i32) -> Colour
[src]
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]
pub fn from(value: u32) -> Colour
[src]
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]
pub fn from(value: u64) -> Colour
[src]
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 Ord for Colour
[src]
pub fn cmp(&self, other: &Colour) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<Colour> for Colour
[src]
impl PartialOrd<Colour> for Colour
[src]
pub fn partial_cmp(&self, other: &Colour) -> Option<Ordering>
[src]
pub fn lt(&self, other: &Colour) -> bool
[src]
pub fn le(&self, other: &Colour) -> bool
[src]
pub fn gt(&self, other: &Colour) -> bool
[src]
pub fn ge(&self, other: &Colour) -> bool
[src]
impl Serialize for Colour
[src]
pub fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl StructuralEq for Colour
[src]
impl StructuralPartialEq for Colour
[src]
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
pub fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
pub fn vzip(self) -> V
impl<T> WithSubscriber for T
[src]
pub fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
[src]
S: Into<Dispatch>,