[][src]Struct serenity::utils::Colour

pub struct Colour(pub u32);

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]

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

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

Returns the red RGB component of this Colour.

Examples

use serenity::utils::Colour;

assert_eq!(Colour::new(6573123).r(), 100);

Returns the green RGB component of this Colour.

Examples

use serenity::utils::Colour;

assert_eq!(Colour::new(6573123).g(), 76);

Returns the blue RGB component of this Colour.

Examples

use serenity::utils::Colour;

assert_eq!(Colour::new(6573123).b(), 67);

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

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]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Deprecated since 0.5.5

: Use the constant instead

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

Trait Implementations

impl PartialOrd<Colour> for Colour
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

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]

Creates a default value for a Colour, setting the inner value to 0.

impl Ord for Colour
[src]

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

impl PartialEq<Colour> for Colour
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl From<i32> for 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]

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]

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]

Constructs a Colour from rgb.

impl Clone for Colour
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Copy for Colour
[src]

impl Eq for Colour
[src]

impl Debug for Colour
[src]

Formats the value using the given formatter. Read more

impl Serialize for Colour
[src]

Serialize this value into the given Serde serializer. Read more

impl<'de> Deserialize<'de> for Colour
[src]

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations

impl Send for Colour

impl Sync for Colour

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

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

🔬 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]

Performs the conversion.

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Mutably borrows from an owned value. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

🔬 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> Erased for T

impl<T> Typeable for T where
    T: Any

Get the TypeId of this object.

impl<T> DebugAny for T where
    T: Any + Debug
[src]

impl<T> CloneAny for T where
    T: Clone + Any
[src]

impl<T> UnsafeAny for T where
    T: Any