diff options
| author | Austin Hellyer <[email protected]> | 2016-11-14 22:06:54 -0800 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2016-11-14 22:06:54 -0800 |
| commit | 83e57f9191c44104addc56537a5fb534b0c4382f (patch) | |
| tree | f845841ae811c75486a04425bb31ccbaf2632183 /src | |
| parent | Allow current user to nickname themselves (diff) | |
| download | serenity-83e57f9191c44104addc56537a5fb534b0c4382f.tar.xz serenity-83e57f9191c44104addc56537a5fb534b0c4382f.zip | |
Decode embed/role colours into Colour struct
This is for a little bit of ergonomics, and is of such a minute cost
that it is worth it to just directly decode the u32's received for
Role/Embed colours into the Colour struct.
Diffstat (limited to 'src')
| -rw-r--r-- | src/model/guild.rs | 10 | ||||
| -rw-r--r-- | src/model/mod.rs | 2 | ||||
| -rw-r--r-- | src/utils/builder/edit_role.rs | 2 | ||||
| -rw-r--r-- | src/utils/colour.rs | 11 |
4 files changed, 14 insertions, 11 deletions
diff --git a/src/model/guild.rs b/src/model/guild.rs index 866cd19..1ab9bb3 100644 --- a/src/model/guild.rs +++ b/src/model/guild.rs @@ -17,7 +17,7 @@ use super::*; use ::utils::builder::{EditGuild, EditMember, EditRole}; use ::client::{STATE, http}; use ::internal::prelude::*; -use ::utils::{Colour, decode_array}; +use ::utils::decode_array; impl From<Guild> for GuildContainer { fn from(guild: Guild) -> GuildContainer { @@ -919,14 +919,6 @@ impl PossibleGuild<Guild> { } impl Role { - /// Generates a colour representation of the role. See - /// [the documentation] on Colour for more information. - /// - /// [the documentation]: ../utils/struct.Colour.html - pub fn colour(&self) -> Colour { - Colour::new(self.colour as u32) - } - /// Deletes the role. /// /// **Note** Requires the [Manage Roles] permission. diff --git a/src/model/mod.rs b/src/model/mod.rs index fc226f9..f21da09 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -28,7 +28,7 @@ use self::utils::*; use std::collections::HashMap; use std::fmt; use ::internal::prelude::*; -use ::utils::decode_array; +use ::utils::{Colour, decode_array}; // All of the enums and structs are imported here. These are built from the // build script located at `./build.rs`. diff --git a/src/utils/builder/edit_role.rs b/src/utils/builder/edit_role.rs index f4fa7ef..d1e2c0e 100644 --- a/src/utils/builder/edit_role.rs +++ b/src/utils/builder/edit_role.rs @@ -37,7 +37,7 @@ impl EditRole { /// Creates a new builder with the values of the given [`Role`]. pub fn new(role: &Role) -> Self { EditRole(ObjectBuilder::new() - .insert("color", role.colour) + .insert("color", role.colour.value) .insert("hoist", role.hoist) .insert("managed", role.managed) .insert("mentionable", role.mentionable) diff --git a/src/utils/colour.rs b/src/utils/colour.rs index b9a3bf5..e2c70e6 100644 --- a/src/utils/colour.rs +++ b/src/utils/colour.rs @@ -1,4 +1,5 @@ use std::default::Default; +use ::internal::prelude::*; macro_rules! colour { ($struct_:ident; $($name:ident, $val:expr;)*) => { @@ -49,6 +50,7 @@ macro_rules! colour { /// [`Role`]: ../model/struct.Role.html /// [`dark_teal`]: #method.dark_teal /// [`get_g`]: #method.get_g +#[derive(Clone, Copy, Debug)] pub struct Colour { /// The raw inner integer value of this Colour. This is worked with to /// generate values such as the red component value. @@ -63,6 +65,15 @@ impl Colour { } } + #[doc(hidden)] + pub fn decode(value: Value) -> Result<Colour> { + match value { + Value::U64(v) => Ok(Colour::new(v as u32)), + Value::I64(v) => Ok(Colour::new(v as u32)), + other => Err(Error::Decode("Expected valid colour", other)), + } + } + /// Returns the red RGB component of this Colour. pub fn get_r(&self) -> u8 { ((self.value >> 16) & 255) as u8 |